NSUndoManager, Core Data and selective undo/redo

做~自己de王妃 提交于 2019-12-04 05:47:53

NSUndoManager waits for the next run loop cycle until it registers your changes

// do your stuff

// give the run loop a breath

[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:[NSDate date]];
[undoManager disableUndoRegistration];

More than a year since this question was posted but anyway here's a answer:

Your should check out apple's Documentation it says:

.. The undo message closes the last open undo group and then applies all the undo operations in that group ... If any unclosed, nested undo groups are on the stack when undo is invoked, it raises an exception. To undo nested groups, you must explicitly close the group with an endUndoGrouping message, then use undoNestedGroup to undo it.

http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/UndoArchitecture/Articles/PerformingUndo.html

My intersection with NSUndoManager is in invalid state, undo was called with too many nested undo groups did not involve CoreData however my answer may be useful none the less.

In my case this the undo manager exception was raised due to an uncaught exception in my code that was raised during a call to NSUndoManager -undo.

Looking back through the console I could see both my app code exception and the undo manager's NSInternalInconsistencyException.

I used the default runloop undo group behaviour and did not explicit group my undo registrations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!