How can i use NSUndo manager to add or remove a subview maybe a textview in the view controller.I have seen many examples for textview text undo redo .But cannot found how to add or remove a view form a view using nsundomanager.
Can anybody help me out please..
what I did to remove a subview from a view using NSUndoManager is saving a "stack" of the subviews in a NSMutableArray.
When the shake gesture is detected and the undoManager is called for undoing, I check if
[self.undoManager isUndoing] and, if that's the case, I call the method that removes the last subview from that array from the current view.
On a note aside, to "Redo" the action, you have to call
prepareWithInvocationTarget again from the method that is undoing, so that it will know how to handle the Redo action in case the user wants to redo. To manage the Redo, I save the point where the subview was added, and if the user wants to redo, I add it again in the same place.