核心数据自动撤消
抱歉,如果这个问题已经得到解决(一如既往),但我找不到明确的答案,所以......
Circa OS X 10.7(我知道的老东西)是我为 Mac 开发的一个核心数据应用程序,它具有“自动" 撤消支持。这是一个核心数据功能。对托管对象上下文的更改只需使用默认的“撤消”菜单即可撤消,无需任何自定义代码行。
这似乎不再适用于这个旧的 Xcode 项目。撤消菜单不执行任何操作并且显示为灰色(相同的应用程序,相同的代码)。
为了检查,我创建了最简单的代码数据应用程序项目(仍然是 Obj-C),是的,它不支持自动撤消。撤消菜单始终显示为灰色,当我向 MOC 的撤消管理器发送 canUndo
消息时,即使我对托管对象进行更改,它也会返回 NO
。
自动撤消不再是核心数据功能吗?我已经太老了吗? (您不必回答这个问题。)
谢谢。
Sorry if this has been already addressed (as always), but I couldn't find a clear answer so...
Circa OS X 10.7 (old stuff I know), a core data app that I was developing for the Mac had "automatic" undo support. This was a core data feature. Changes to the managed object context were simply undoable with the default "undo" menu without any custom line of code.
This no longer appear to work on this old Xcode project. The undo menu doesn't do anything and is greyed out (same app, same code).
To check, I created the most simple code data app projet (still Obj-C), and yep, it doesn't support automatic undo. The undo menu is always greyed out and when I send canUndo
messages to the MOC's undo manager, it returns NO
even after I make changes to managed objects.
Is automatic undo no longer a core data feature? Am I already too old? (You don't have to answer this one.)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的托管对象上下文的
undoManager
很可能是 nil,这是默认值。 Core Data 无法单独撤消,但可以与撤消管理器配合使用。创建一个或传入一个已存在的管理器 - 例如,NSDocument
有一个撤消管理器,并且您的应用程序委托可能有一个。Most likely your managed object context's
undoManager
is nil, which is the default value. Core Data can't undo on its own but it can work with an undo manager. Either create one or pass in one that already exists-- for example,NSDocument
has an undo manager, and your app delegate might have one.感谢 Tom 的输入和对该问题。
macOS 核心数据应用程序不再默认设置撤消管理器。他们以前曾经有过一个(如上面链接的问题的回复所示)。
要将撤消管理器添加到托管对象上下文,我只需将这些代码行添加到
AppDelegate.m
的NSManagedObjectContext
方法中(就在return
之前) code> line):并且撤消再次起作用。
That was a simple fix thanks to Tom's input and the answer to that issue.
macOS core data apps no longer have an undo manager set by default. They used to have one before (as indicated in the response to the issue linked above).
To add an undo manager to the managed object context, I just added these lines of code to the
NSManagedObjectContext
method ofAppDelegate.m
(just before thereturn
line):and undo works again.