Undo and Redo As the user makes changes, for example while entering text, it is sometimes desirable to discard recent changes and go back to a previous state. iOS has an NSUndoManager that helps with this, and the basic operation is rather simple. At some point you save the state, say the text you are entering. The Undo Manager does that. Later, you can ask the Undo Manager to discard the present state and restore the earlier state. The Undo Manager maintains a stack of previous states, so one can step back as far as you wish. To prevent exhausting memory there is a way to limit the size of the stack. In addition, if you step back one or more positions on the stack, the later positions remain, and you can return to them, called a Redo. However, if you step back and make a change, the later positions are discarded because they represent a fork in your intentions and are no longer relevant. Since entering text is the most common use for Undo, there is an Undo Manager built into UIResponder that operates automatically and responds to a shake of the device to cause an undo. This demo project shows both. The page was last updated
Thursday, November 6, 2014 11:02 AM
|