NSManagedObject 与 NSArrayController 的关系
我得到的是:
- controller1一个
NSArrayController
- controller2一个
NSArrayController
。这与controller1 的属性具有父关系。 - controller1-2Tree 一个
NSTreeController
和一个NSOutlineView
来查看它。这显示了controller1的层次结构以及从controller2的父/子关系中找到的每个项目的子项。这是通过将两个 NSArrayController 绑定到树的值和子节点来完成的。
问题:
在我的情况下,一切都使用核心绑定。然而,与 NSTableView
不同,我的 NSOutlineView
的非正统设置意味着我当前的选择不会传递到相关的 NSArrayController
上。例如,如果我在 controller1-2Tree 中选择一个子级,它是我的 controller2 中的一个对象,但 controller2 本身并不注册选择改变。
我有相关的代码来获取选择更改。我不确定如何手动更改 controller2 或 controller1 的当前选择项(尽管我现在需要的是 2),基于了解当前选择的项目控制器1-2树。
我已经弄清楚了如何隔离当前选定的对象,只是缺少最后一步如何将其与 NSArrayController 相关联,而无需基于尝试匹配属性来迭代它。
NSManagedObject *selectedObject = [[controller1-2View itemAtRow:[controller1-2View selectedRow]] representedObject];
NSManagedObjectContext *selectedObjectContext = [selectedObject managedObjectContext];
What I've got:
- controller1 an
NSArrayController
- controller2 an
NSArrayController
. This has a parent relationship to an attribute of controller1. - controller1-2Tree an
NSTreeController
and anNSOutlineView
to view it. This shows the hierarchy of controller1 and the children of each item that it found from the parent/child relationship of controller2. This has been done by binding the twoNSArrayControllers
to the values and children of the tree.
The Problem:
Everything in my situation uses core-bindings. Yet, unlike an NSTableView
, the unorthodox set up of my NSOutlineView
means that my current selection isn't passed onto my relevant NSArrayController
. For example, if I select a child in my controller1-2Tree, it's an object from my controller2, but controller2 itself doesn't register the selection change.
I have the relevant code to pick up on selection changes. I'm unsure of how to manually change the current selection item of controller2 or controller1 (although it's 2 that I need right now), based on knowing the current selected item of controller1-2Tree.
I've worked out how to isolate the currently selected object, I'm just missing the last step on how to relate this to the NSArrayController
without iterating through it based on trying to match a property.
NSManagedObject *selectedObject = [[controller1-2View itemAtRow:[controller1-2View selectedRow]] representedObject];
NSManagedObjectContext *selectedObjectContext = [selectedObject managedObjectContext];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我走了一条我试图避免的艰难之路,并通过迭代对象和控制器来实现它。我确信有比这更好的方法。
Ok, I went the hard way that I was trying to avoid and got this to work by iterating through objects and controllers. I'm sure there's a better way than this.