2012-09-19 2 views
3

iOS 6이 서식있는 텍스트 편집을 위해 UITextView를 사용하도록 업데이트되었습니다. (UITextView는 이제 바뀔 수없는 바꿔서 attributText 속성을 얻습니다. 다음은 NOS에서 iOS 6 Apple 포럼에서 iOS 6이 공개 된 이후 공개 될 수있는 질문입니다. ...UITextView 실행 취소 관리자가 대체 속성 문자열 (iOS 6)을 사용하여 작동하지 않습니다.

UITextView에서 UITextView에서 글꼴 변경을 취소 할 수는 있지만 사본을 대체 할 수는 없습니다. 뷰의 속성 캐릭터 라인 이 코드를 사용할 때 ...

- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new 

{ 
1. [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old]; 
2. old=new; 

} 

... 취소가 잘되고 있습니다.

그러나 내가보기에 결과를 볼 얻을 수있는 라인을 추가하는 경우를 UndoManager가 발생하지 않는 "대체 :와 :"방법 예상대로 ...

- (void) replace: (NSAttributedString*) old with: (NSAttributedString*) new 

{ 
1. [[myView.undoManager prepareWithInvocationTarget:self] replace:new with:old]; 
2. old=new; 
3. myView.attributedText=[[NSAttributedString alloc] initWithAttributedString:old]; 

} 

어떤 생각을? MutableAttributedString에 대해 "2"줄에서 사용하려고 시도한 대체 방법 중 하나와 동일한 문제가 있습니다 ...

답변

0

실행 취소 관리자는 'text'또는 'attributedText '속성, 이것이 작동하지 않는 이유입니다. 이 동작이 버그인지 설계 상 나는 몰라요.

그러나 대신 UITextInput 프로토콜 방법을 사용할 수 있습니다.

  • (무효)는, replaceRange (있는 NSString *) 텍스트이 작동

: (UITextRange *)는 withText를 다양합니다.

+1

고마워요. 그러나 문제는이 프로토콜이 attributedString을 대체 할 수 없으며 NSString 만 대체 할 수 있다는 것입니다. – Denis

1

음, 와우 나는 이것이 실제로 작동 할 것이라고 기대하지 않았다! 나는 해결책을 찾지 못했기 때문에 나는 무엇이든 시도해보기 시작했습니다 ...

- (void)applyAttributesToSelection:(NSDictionary*)attributes { 
    UITextView *textView = self.contentCell.textView; 

    NSRange selectedRange = textView.selectedRange; 
    UITextRange *selectedTextRange = textView.selectedTextRange; 
    NSAttributedString *selectedText = [textView.textStorage attributedSubstringFromRange:selectedRange]; 

    [textView.undoManager beginUndoGrouping]; 
    [textView replaceRange:selectedTextRange withText:selectedText.string]; 
    [textView.textStorage addAttributes:attributes range:selectedRange]; 
    [textView.undoManager endUndoGrouping]; 

    [textView setTypingAttributes:attributes]; 
}