将NSUndoManager撤消更改发生在后台? [英] Will NSUndoManager undo changes happening in the background?

查看:240
本文介绍了将NSUndoManager撤消更改发生在后台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编辑视图控制器,我使用的NSUndoManager是为我的持久存储(核心数据项目)设置的。

I've got an edit view controller which I'm using an NSUndoManager for which is the one set for my persistence store (core data project).

一个的我的应用程序的功能是与外部服务器同步。我想知道的是,如果我在我的视图中编辑的东西,同时应用程序正在与服务器同步,如果我改变主意,并决定撤消我当前的编辑的任何更改,还会撤消

One of the features of my app is synchronisation with an external server. What I want to know is, if I am editing something in my view, and at the same time the app is syncing itself with the server, if I change my mind and decide to undo any changes in my current edit, would it also undo all of the changes made during the sync if they were made whilst the undo grouping had started, or would it only undo changes I'd made myself?

推荐答案

取决于您的实现。通常,undo管理器为您的事件打开一个undo组并封装更改,请参阅groupsBeEvent。如果您使用辅助管理对象上下文进行后台同步,并将上下文合并到主上下文
中,则必须确保禁用了撤销注册,请参阅disableUndoRegistration。

Depends on your implementation. Normally, the undo manager open an undo group for your event and encapsulates the changes, see groupsByEvent. If you use a secondary managed object context for your background synchronization and merge the context back in to the main context you have to ensure that you disabled the undo registration, see disableUndoRegistration.

编辑:
这是一个小代码片段,您可以在不创建撤消操作的情况下在单独的上下文中同步

Here is a little code snippet with that you can synchronize in a separate context without creating undo actions

// create a child context with no undo manager
NSManagedObjectContext *context = [NSManagedObjectContext contextWithParent:self.managedObjectContext];
context.undoManager = nil;

[... do your synchronization with the child context...]

// merge into main context without generating undo actions
[undoManager disableUndoRegistration];
[context save:&error];
[managedObjectContext processPendingChanges];
[undoManager enableUndoRegistration];

// to prevent undo action beyond the synchronization to remove all undo actions
[undoManager removeAllActions];

这篇关于将NSUndoManager撤消更改发生在后台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆