将实体绑定为 NSTreeController 子级的正确方法
我对如何使用绑定到两个独立实体的 NSTreeController
填充 NSOutlineview
的理解是否正确:
我的 NSTreeController
code> 有一个托管对象上下文绑定到我的 appDelegate
。我的对象控制器
是一个名为客户端的实体。我的 NSOutlineViews
tableColumn
绑定到 NSTreeController
(和客户端)关键路径
< strong>clientCompany ,这会使用公司名称列表正确填充我的 NSOutlineView
。
我的第二个实体 projects 具有一个名为 projectParent 的关系属性,与客户端中名为 clientChild 的属性反向绑定。通过这种关系,我希望我的 NSTreeController
的子级由以相关 clientCompany 作为父级的相关 projects 条目组成。
为了尝试这一点,我在我的 NSTreeController
中将 clientChild 设为 children
key path
,然后绑定我的 content使用
设置为我的clients实体的clientChildController Key
将同一控制器的key path
作为“选定”。
这种方法和各种组合似乎不起作用并产生不同的错误。只有当我省略最后一个“内容集
”绑定步骤时,程序才会在启动时运行而不会出现错误,并且在大纲视图条目旁边有打开/关闭图标,表明它按照我想要的方式填充。尝试打开其中一个条目时,它会生成一个错误,表明我的 projects 实体不符合我的 clientChild 属性的 KVC 要求。我已经检查了一遍又一遍的绑定,似乎找不到问题。
Am I correct in my understanding of how to populate an NSOutlineview
with an NSTreeController
who is bound to two seperate entities that have a relationship between them:
My NSTreeController
has a managedObjectContext bound to my appDelegate
. My Object Controller
for this is an entity named clients. My NSOutlineViews
tableColumn
is bound to the NSTreeController
(and clients) key path
clientCompany and this populates my NSOutlineView
correctly with a list of company names.
My second entity, projects, has a relationship property called projectParent inverse-bound to a property in clients called clientChild. Through this relationship, I want the children of my NSTreeController
to be made up of the relevant projects entries that have the relevant clientCompany as a parent.
To attempt this, I made clientChild the children
key path
in my NSTreeController
and then bound my content set
of the same controller to the clientChild key path
of my clients entity with the Controller Key
as 'selected'.
This method and various combinations don't seem to work and produce varying errors. It's only if I leave out that last 'content set
' binding step that the program runs without errors on startup and has open/close icons next to the the outlineview entries, suggesting it populated like I wanted. On trying to open one of the entries, it produces an error suggesting my projects entity isn't KVC compliant with my clientChild property. I've gone over and over the bindings and can't seem to find the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一周多的阅读和研究,我相信答案是这是不可能的。这让我有点惊讶 - 考虑到 Interface Builder 和 NSTreeController 提供的所有节省时间的快捷方式,我认为我的情况很常见,可以在 Interface Builder 或内置类中实现。
我没有在创建自己的类来做我想做的事情,希望这个答案对任何正在搜索这个并且找不到很多答案的人有用(谷歌没有多大用处)。
From over a weeks worth of reading and researching, I believe the answer is that this isn't possible. This surprises me a little - considering all the time saver shortcuts that Interface Builder and NSTreeController provide, I thought my situation was common enough that this would have been implemented in Interface Builder or a built-in class.
I'm not in the process of creating my own class to do what I want and hopefully this answer is useful to anybody who was searching for this and couldn't find many answers (google wasn't much use).