The Undo Interface
We must now decide how to let the user request Undo and Redo. In testing the code from the preceding section, I used two buttons, an Undo button that sent undo
to the NSUndoManager and a Redo button that sent redo
to the NSUndoManager. This can be a perfectly reasonable interface, but let’s talk about some others.
By default, your application supports shake-to-edit. This means the user can shake the device to bring up an undo/redo interface. We discussed this briefly in Chapter 35. If you don’t turn off this feature by setting the shared UIApplication’s applicationSupportsShakeToEdit
property to NO, then when the user shakes the device, the framework walks up the responder chain, starting with the first responder, looking for a responder whose undoManager
property returns an actual NSUndoManager instance. If it finds one, it puts up the undo/redo interface and communicates appropriately with that NSUndoManager, depending on the user’s choice in that interface.
You will recall what it takes for a UIResponder to be first responder in this sense: it must return YES from canBecomeFirstResponder
, and it must actually be made first responder through a call to becomeFirstResponder
. Let’s suppose that MyView satisfies these requirements (for example, we might call becomeFirstResponder
at the start of dragging:
). Then, to make shake-to-edit work, we must also set its undoManager
property instead of its undoer
property as we are now doing. However, the inherited undoManager ...
Get Programming iOS 4 now with O’Reilly online learning.
O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.