观察 NSTreeController 绑定的 CoreData 实体以进行插入/删除
我正在创建自己的可绑定自定义树视图。为此,我想观察 NSTreeController 来更新其项目的多对多关系。 NSTreeController 绑定到 CD 管理对象上下文。每个深度级别都有自己的 CD 实体,具有parent/children/isLeaf 属性。我需要在视图中保持相同的层次结构(以及项目子项的顺序)。如果插入了某些东西,我将开始观察它的子属性。当然,我需要知道新插入的对象的索引路径。
我想确切地知道插入/删除了什么,这样我就可以开始观察它的子项插入/删除情况。据我了解,执行此操作的标准方法是在observeValue:forKey ...中查找“更改”NSDictionary,但更改为NULL。
我知道这是一个很长的错误,但是有一些好的解决方法吗?我已经看到一些示例的视图保存数组,然后当模型更改时,您可以比较差异。对于树视图来说更复杂。这种方式还会浪费内存和 CPU 周期。 我正在测试一种解决方法。它只是有效,所以我不会描述它。
I am creating my own bindable custom treeview. For that I would like to observe NSTreeController for updates to its items' to-many-relationships. NSTreeController is bound to CD managed object context. Every depth level has its own CD Entity with parent/children/isLeaf properties. I need to maintain same hierarcy in the view (and order of items children). If something is inserted, i will start observing its children property. And i need to know indexpath for the newly inserted object ofcourse.
I would like to know exactly what was inserted/removed, so i can start observing it for insertions/removals to its children. As i understand, standard way to do this is looking into "change" NSDictionary inside observeValue:forKey..., but changes are NULL.
I know that this is a long time bug but is there some GOOD workaround for it? I've seen that some examples' views save arrays and then when the model changes, you compare for differences. Its more complicated for treeview. Also this way wastes memory and CPU cycles.
I have one workaround that i am testing. It just kind of works so i will not describe it yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何子类化 NSTreeController 并实现其插入/删除方法。例如这样的事情。
How about subclassing NSTreeController and implementing its insert/remove methods. Something like this for example.