Unite UITextView dispatcher does not work with assignment string replacement (iOS 6)

iOS 6 has been updated to use UITextView to edit rich text (UITextView now gets the attributedText property, which doesn’t stupidly change). Here is the question asked on the Apple iOS 6 forum under the NDA, which can be made public, since iOS 6 is now publicly ...

In UITextView, I can undo any font change, but I cannot undo the replacement in the copy of the string associated with the view. When using this code ...

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

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

}

... destruction works well.

But if I add a line to get the result visible in my view, undoManager does not run the "replace: with:" method, as it should ...

- (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"...

+3
2

, , , ! , ...

- (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];
}
+1

Undo reset "text" "attributedText", . , .

UITextInput.

  • (void) replaceRange: (UITextRange *) range withText: (NSString *)

.

0

All Articles