Undo/redo with a UITextView (iOS/iPHone)

后端 未结 3 1796
逝去的感伤
逝去的感伤 2020-12-15 01:49

I have a view where a UITextView always has focus. What I want to do is extend the built-in undo/redo behavior to support undo/redo for when I programmatically set the text

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 02:38

    You can change your textview to whatever text you want and preserve undo and redo manager's memory stacks. self.content is UITextView.

    -(void) yourClearAllButtonIsPressed
    {
        [[self.content.undoManager prepareWithInvocationTarget:self] undoClear:self.content.text];
        [self.content setText:@""];//Or something else you want to change your textview to
    }
    
    }
    

    //just one, my method I created

    -(void) undoClearBlablabla:(NSString*) text
        {
            [[self.content.undoManager prepareWithInvocationTarget:self] undoClear:self.content.text];
            [self.content setText:text];
        }
    

提交回复
热议问题