In my iOS application's interface I have explicit undo & redo button (shake-to-undo is a pretty heavyweight action and in this context, undos are performed pretty frequently). Normally, I would use KVO to observe NSUndoManager's canUndo and canRedo key paths and enable & disable the buttons as the notifications come in. Unfortunately, NSUndoManager doesn't seem to be KVO-compliant for those key paths -- or at least, I'm not seeing anything in terms of notifications.
So my question is: How do I get this working? Am I just doing it wrong with KVO? (I've double & triple checked but there's always that possibility). Is there another way to do this that I'm not thinking of? (I've though about just checking the value of -canUndo every time the runloop spins but that has kind of a bad code smell to me).
(Note that it's quite possible that NSUndoManager is different on the iOS and Mac OS X, so I don't think "It works on the Mac" is going to be a helpful answer, in this case)
Register for your NSUndoManager's NSUndoManagerDidUndoChangeNotification and friends to examine when new undo groups are created and popped off the stack and update your button's states appropriately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With