核心数据和选择性撤销

核心数据和选择性撤销

本文介绍了NSUndoManager,核心数据和选择性撤销/重做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个核心数据应用程序,它具有类似于树的管理对象的相当大的层次结构。

I'm working on a core data application that has a rather large hierarchy of managed objects similar to a tree.

创建基础对象时,一些子对象继而创建自己的子对象等等。这些子对象中的每一个都可以使用NSURLConnections来收集信息。

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.

现在,我想在managedObjectContext中使用undoManager来支持undo / redo。问题是,如果用户创建一个基础对象,然后尝试撤消该操作,基础对象不会被删除。相反,可以移除一个或多个子对象。显然,这种类型的操作是不可预测的和不需要的。

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.

所以我试图禁用默认情况下的撤消注册。我通过调用 disableUndoRegistration:之前在managedObjectContext中修改任何内容。

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:

思考?

推荐答案

NSUndoManager等待下一个运行循环周期,直到它注册您的更改

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];

这篇关于NSUndoManager,核心数据和选择性撤销/重做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:20