views:

79

answers:

1

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)

+1  A: 

Register for your NSUndoManager's NSUndoManagerDidUndoNotification and friends to examine when new undo groups are created and popped off the stack and update your button's states appropriately.

Ashley Clark
Awesome -- NSUndoManagerWillCloseUndoGroupNotification is the one I had missed previously. Everything makes sense now. Thanks @aclark.
Colin Barrett
One last follow up: That all worked perfectly.
Colin Barrett