核心数据自动撤消

发布于 2025-01-12 01:56:49 字数 430 浏览 1 评论 0原文

抱歉,如果这个问题已经得到解决(一如既往),但我找不到明确的答案,所以......

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最后的乘客 2025-01-19 01:56:49

您的托管对象上下文的 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.

温柔一刀 2025-01-19 01:56:49

感谢 Tom 的输入和对该问题。

macOS 核心数据应用程序不再默认设置撤消管理器。他们以前曾经有过一个(如上面链接的问题的回复所示)。

要将撤消管理器添加到托管对象上下文,我只需将这些代码行添加到 AppDelegate.mNSManagedObjectContext 方法中(就在 return 之前) code> line):

NSUndoManager *undoManager = [[NSUndoManager alloc] init];
[_managedObjectContext setUndoManager:undoManager];

并且撤消再次起作用。

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 of AppDelegate.m (just before the return line):

NSUndoManager *undoManager = [[NSUndoManager alloc] init];
[_managedObjectContext setUndoManager:undoManager];

and undo works again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文