即使撤消显示尽可能,在 NSPersistentDocument 中创建新的 NSManagedObject 也拒绝保存
我有一个 CoreData / NSPersistentDoc 应用程序。效果很好。
我向 MOM 添加了一个新实体,并更新了版本。
现在,当我在 MOC 内创建该实体的新实例时,“保存”菜单项将保持禁用状态,直到/除非我创建应用程序中已存在的旧实体的任何实例。
标题栏上的红点按钮正确变黑,表明文档已更改 - 但 OS X / NSDocument 拒绝承认这一点 - 无法进行保存。
有什么想法吗?
I have a CoreData / NSPersistentDoc app. It works fine.
I added a new entity to the MOM, and updated the version.
Now, when I create new instances of that Entity inside the MOC, the "Save" menu item remains disabled until/unless I create any instances of the old Entities that were already in the app.
The red dot button on titlebar correctly goes black to show that the document has changed - but OS X / NSDocument refuses to acknowledge this - it is impossible to do a Save.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了原因/解决方案 - 这是我自己的错误,但这个答案可能会帮助其他遇到类似问题的人。
我使用 Apple 的官方方法来启用复制/粘贴菜单项(通过实现 validateMenuItem),并在正确的时间返回 true/false 进行复制和粘贴。
我正在返回 NSPersistentDocument 的其他所有内容的实现(其中包括 Save,尽管我没有看到)。
然后,当我添加新的 NSManagedObject 时,我添加了一个子视图和子视图控制器,并将 validateMenuItem 委托给了它 - 即,以便它可以处理它自己的复制/粘贴状态。
...但是我没有代码路径“如果它不是复制粘贴,并且它不是由子类处理的,并且它不是由我的 NSPersistenDocument 子类处理的...然后将其交给 NSPersistenDocument 来决定”...
...因此“保存”菜单项从未被启用。
I found the cause / solution - it was my own bug, but this answer may help others with similar issues.
I was using Apple's official approach for enabling the Copy/Paste menu items (by implementing validateMenuItem), and returning true/false for copy and paste at the right times.
And I was returning NSPersistentDocument's implementation for everything else (which included Save, although I didn't see that).
Then, when I added my new NSManagedObject, I added a sub-view, and sub-view-controller, and I delegated the validateMenuItem to this - i.e. so that it could handle it's own copy/paste status.
...but I had no code path for "if it's not copy paste, and it's not handled by the child, and it's not handled by my NSPersistenDocument subclass ... then hand it to NSPersistentDocument to decide"...
...and so the Save menuitem was never being enabled.