문제

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?
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top