IOS - UITextView + NSUndoManager

I am trying to integrate the undo / redo functions into a UITextView (I am creating a LateX editor) with no luck, and to be honest, I'm really confused by this argument. I do not understand the steps associated with these two operations, I mean, I need two methods

  • one to delete the last inserted text
  • one to restore deleted text.

Is there any doubt when I get the last inserted text? in other words, where should I register for cancellation?

  • in textViewDidChange I can get all the text
  • in textViewShouldChangeTextInRange I can get the last char inserted

I know that what I wrote was not the best explanation, but I hope that someone here has encountered the same problem in the past and can give me a hint. Basically, to resume, I have to add undo / redo functions to the text view, possibly with two buttons associated with these actions.

Thanks in advance

+8
ios cocoa-touch uitextview uitextviewdelegate nsundomanager
source share
1 answer

I feel like an idiot right now :( the solution was really very easy ... TextView already has an undoManager, so basically steps for undo / redo actions for textView: inside viewDidload:

myUndoManager = [textView undoManager]; 

where do you want to perform actions

 [myUndoManager undo]; // or redo 

I'm really dumb sometimes, I almost wrote my own cancellation code ... Hope this can help someone

+22
source share

All Articles