NSUndoManager、核心数据和选择性撤消/重做
我正在开发一个核心数据应用程序,该应用程序具有相当大的托管对象层次结构,类似于树。
创建基础对象时,它会创建一些子对象,这些子对象又创建自己的子对象,依此类推。这些子对象中的每一个都可以使用 NSURLConnections 收集信息。
现在,我想使用 ManagedObjectContext 中的 undoManager 支持撤消/重做。问题是,如果用户创建一个基础对象,然后尝试撤消该操作,则该基础对象不会被删除。相反,可以移除一个或多个子对象。显然,这种类型的行为是不可预测的并且是不需要的。
所以我尝试默认禁用撤消注册。我通过在 ManagedObjectContext 中进行任何修改之前调用 disableUndoRegistration:
来完成此操作。然后,在创建基础对象等基本操作之前启用撤消注册,然后再次重新禁用注册。
现在,当我尝试撤消时,我收到此错误:
撤消:NSUndoManager 0x1026428b0 位于 无效状态,调用撤消 嵌套撤消组过多
有想法吗?
I'm working on a core data application that has a rather large hierarchy of managed objects similar to a tree.
When a base object is created, it creates a few child objects which in turn create their own child objects and so on. Each of these child objects may gather information using NSURLConnections.
Now, I'd like to support undo/redo with the undoManager in the managedObjectContext. The problem is, if a user creates a base object, then tries to undo that action, the base object is not removed. Instead, one or more of the child objects may be removed. Obviously this type of action is unpredictable and unwanted.
So I tried disabling undo registration by default. I did this by calling disableUndoRegistration:
before anything is modified in the managedObjectContext. Then, enabling undo registration before base operations such as creating a base object the again re-disabling registrations afterwords.
Now when i try to undo, I get this error:
undo: NSUndoManager 0x1026428b0 is in
invalid state, undo was called with
too many nested undo groups
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSUndoManager 等待下一个运行循环周期,直到它注册您的更改
NSUndoManager waits for the next run loop cycle until it registers your changes
自从这个问题发布以来已经一年多了,但无论如何这里有一个答案:
你应该查看苹果的文档,它说:
http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/UndoArchitecture/Articles/PerformingUndo.html
More than a year since this question was posted but anyway here's a answer:
Your should check out apple's Documentation it says:
http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Conceptual/UndoArchitecture/Articles/PerformingUndo.html
我与 NSUndoManager 的交集处于无效状态,调用撤消时使用了太多嵌套撤消组 不涉及 CoreData,但我的答案可能仍然有用。
在我的例子中,撤消管理器异常是由于我的代码中在调用 NSUndoManager -undo 期间引发的未捕获异常而引发的。
回顾控制台,我可以看到我的应用程序代码异常和撤消管理器的 NSInternalInconsistencyException。
我使用了默认的运行循环撤消组行为,并且没有明确对我的撤消注册进行分组。
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.