NSUndoManager and enable / disable the cancel button

In my iOS application interface, I have an explicit cancel and redo button (shake-to-undo is a pretty tough action, and cancellation is done quite often in this context). I usually use KVO to monitor the NSUndoManager canUndo and canRedo keys, as well as toggle buttons on and off when notifications appear. Unfortunately, NSUndoManager does not seem KVO-compatible for these key paths - or at least m without seeing anything in terms of notifications.

So my question is: how do I get this to work? Am I just doing it wrong with KVO? (I checked twice and three, but there is always such an opportunity). Is there any other way to do this that I don't think about? (I only mean checking the -canUndo value every time the runloop spins, but I have a bad code smell).

(Note that it is entirely possible that NSUndoManager is different from iOS and Mac OS X, so I don’t think that β€œIt works on Mac” would be a useful answer in this case)

+7
cocoa-touch nsundomanager
source share
1 answer

Register NSUndoManager NSUndoManagerDidUndoChangeNotification and friends to find out when new undo groups are created and popped out of the stack and update button states accordingly.

+12
source share

All Articles