在 Xcode 中使用绑定进行底层修补

发布于 2024-08-13 04:54:02 字数 526 浏览 3 评论 0原文

让我们采用两个核心数据实体,设置如下:

实体 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无悔心 2024-08-20 04:54:02

有关当前如何设置它的更多信息将会有所帮助。您应该能够以与其他属性完全相同的方式绑定到数组控制器,并使用相同的绑定和控制器密钥。只需使用完整的密钥路径 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 (in Entity mode). Then, you create a secondary, 'detail' array controller. Leave the detail array controller in Class mode (with the default NSMutableDictionary class), and bind its content set to your master array controller, with the controller key set to selection and the model key path to cars.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文