简体   繁体   English

将实体绑定为NSTreeController的子代的正确方法

[英]Correct method to bind an entity as children of an NSTreeController

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: 我对使用NSTreeController填充NSOutlineview理解是否正确,该NSTreeController绑定到两个相互独立的实体,它们之间具有关系:

My NSTreeController has a managedObjectContext bound to my appDelegate . 我的NSTreeController有一个绑定到我的appDelegate的managedObjectContext。 My Object Controller for this is an entity named clients . 为此,我的Object Controller是一个名为客户端的实体。 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. 我的NSOutlineViews tableColumn绑定到NSTreeController (和客户端key path clientCompany ,这正确地用公司名称列表填充了NSOutlineView

My second entity, projects , has a relationship property called projectParent inverse-bound to a property in clients called clientChild . 我的第二个实体project具有一个名为projectParent的关系属性,该属性反向绑定到客户端中名为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. 通过这种关系,我希望我的NSTreeController的子级由具有相关clientCompany作为父级的相关项目条目组成。

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'. 为此,我在我的NSTreeController 中将clientChild设置children key path ,然后将同一控制器的content set绑定到我的客户端实体的clientChild key path ,并将Controller Key为“ 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. 仅当我忽略了最后一个“ content set ”绑定步骤后,程序在启动时运行就没有错误,并且大纲视图条目旁边有打开/关闭图标,提示它按我的意愿进行了填充。 On trying to open one of the entries, it produces an error suggesting my projects entity isn't KVC compliant with my clientChild property. 尝试打开其中一个条目时,它产生一个错误,表明我的项目实体与我的clientChild属性不兼容KVC。 I've gone over and over the bindings and can't seem to find the problem. 我已经遍历了绑定,似乎找不到问题。

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. 这让我有些惊讶-考虑到Interface Builder和NSTreeController提供的所有节省时间的快捷方式,我认为我的情况很普遍,因此可以在Interface Builder或内置类中实现。

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). 我没有创建自己的班级来完成自己想要的事情,并且希望此答案对正在搜索此内容并且找不到很多答案的人有用(谷歌用处不大)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM