在 Xcode 中使用绑定进行底层修补
让我们采用两个核心数据实体,设置如下:
实体 A:汽车
Attributes:
year
model
Relationships:
manufacturer (<<-> Manufacturer)
实体 B:制造商
Attributes:
name
country
Relationships:
cars (<->> Car)
现在,我要做的是将显示绑定到 NSTableView,其中我们有汽车的模型一列,后面是制造商,然后是年份。绑定模型和年份没有问题,但如果我将关系绑定到表中的列,我会在该列的每个单元格中得到关系错误错误的文本,而不是我正在寻找的任何内容。 我如何使用绑定来显示与汽车相关的正确制造商名称?
进一步扩展问题,我如何设置另一个表格视图来显示其他< code>Car 条目具有相同的manufacturer
关系?
Let's take two Core Data entities, set up as follows:
Entity A: Car
Attributes:
year
model
Relationships:
manufacturer (<<-> Manufacturer)
Entity B: Manufacturer
Attributes:
name
country
Relationships:
cars (<->> Car)
Now, what I want to do is bind the display to an NSTableView
where we have the model of the car in one column, followed by the manufacturer, followed by the year. Binding the model and year are no problem, but if I bind the relationship to a column in the table, I get the text of a relationship fault error in each cell in that column instead of anything I'm looking for. How can I play with the binding to allow me to display the proper manufacturer name associated with the car?
Extending the question a bit further, how could I set up another table view to display, say, other Car
entries with the same manufacturer
relationship?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有关当前如何设置它的更多信息将会有所帮助。您应该能够以与其他属性完全相同的方式绑定到数组控制器,并使用相同的绑定和控制器密钥。只需使用完整的密钥路径
manufacturer.name
作为模型密钥路径。对于一对多关系,您可以使用两个数组控制器。设置“主”数组控制器以从 Core Data
Manufacturer
类(在Entity
模式下)准备自己的内容。然后,您创建一个辅助的“详细”阵列控制器。将详细数组控制器保留为Class
模式(使用默认的NSMutableDictionary
类),并将其内容集绑定到主数组控制器,并将控制器键设置为选择
和汽车
的模型关键路径。现有的许多教程正是这样做的。我强烈建议您浏览一两个;我找到了这个 MacResearch.org 教程 特别有帮助。整个系列都很棒。
A bit more information about how you have it set up currently would be helpful. You should be able to bind to your Array Controller in exactly the same fashion as your other attributes, with the same binding and controller key. Just use the full key path
manufacturer.name
for the model key path.For a to-many relationship, you use two array controllers. Set up the 'master' array controller to prepare its own content from your Core Data
Manufacturer
class (inEntity
mode). Then, you create a secondary, 'detail' array controller. Leave the detail array controller inClass
mode (with the defaultNSMutableDictionary
class), and bind its content set to your master array controller, with the controller key set toselection
and the model key path tocars
.Many many tutorials exist out there that do exactly this. I highly recommend running through one or two; I found this MacResearch.org tutorial particularly helpful. The entire series is great.