Question

I have a CoreData based application which supports shake-to-undo. This is currently working fine, however when I shake the device, the undo happens immediately, without first showing the usual undo prompt which NSUndoManager normally provides for free.

I've read "Using Undo on iPhone" from the "Undo Architecture" document and am:

  • implementing canBecomeFirstResponder, returning YES
  • making the view controller becomeFirstResponder in viewDidAppear
  • making the view controller resignFirstResponder in viewDidDisappear
  • redeclaring the self.undoManager in the view controller as read/write
  • creating an NSUndoManager and setting self.undoManager in the UIViewController init method (which I've verified is getting called).
  • setting self.managedObjectModel.managedObjectContext.undoManager to self.undoManager in the setter for managedObjectModel. Again, I've verified this is getting called. If I don't do this, undo doesn't work at all.

Troubleshooting I've already tried:

  • checking undo does in fact work (I see changes to my managedObjectModel reverted)
  • verifying canBecomeFirstResponder is being called
  • checking if accessor self.undoManager is being called during an undo operation (which it is not).

So my questions are:

  • under what circumstances does undo work but not show the undo prompts?
  • What would you try next to troubleshoot this?
Was it helpful?

Solution

I eventually tracked this down to some legacy code which was manually catching the shaking motion and calling undo on the undoManager; an implementation of motionEnded: in the view controller. Once this was removed, I started getting undo prompts again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top