“控制器键”是什么意思? Interface Builder 中的平均值> 检查员> 绑定?

发布于 2024-07-14 10:50:54 字数 49 浏览 14 评论 0原文

我在文档中找不到他们解释所有这些字段及其含义的地方。 尤其是“控制器键”我不清楚。

I can't find in the Docs where they explain all those fields and what they mean. Especially "Controller Key" is not clear to me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

二手情话 2024-07-21 10:50:54

[复制我对另一个问题的回答...]

控制器键是您要绑定的(控制器对象的属性)的键。 模型关键路径是绑定对象可以向模型对象询问更基本的对象(例如字符串或图像)或其他模型对象(即深入模型)的关键路径。

示例:假设数组控制器中有一个 Person 对象,每个 Person 都有一个名称。 您将表列绑定到数组控制器、控制器键 arrangedObjects (从而获取模型对象)、模型键路径 name (从而获取值对象)。

一个更复杂的示例:假设您有一个 Departments 数组控制器。 每个部门都包含人员(部门中的员工)。 您可以将 People 数组控制器绑定到 Departments 控制器、控制器键 arrangedObjects (获取 Department 模型对象)、模型键路径 @distinctUnionOfObjects.employees (获取 Person 模型对象) ),然后将表列绑定到 People 控制器、控制器键 arrangedObjects、模型键路径 name

那张桌子是为你公司工作的人准备的; 如果您有一个单独的潜在员工表,您也可以为他们创建 Person 对象,并且他们不会显示在现有员工的表中,因为他们不在部门中。 当您雇用他们时,您会将他们添加到一个或多个部门; 然后,他们将自动显示在人员数组控制器中,因为该数组控制器正在观察所有部门的员工

[Copying my answer on another question…]

The controller key is the key for the (property of the controller object) you're binding to. The model key path is the key path by which the bound object can ask the model objects for more basic objects, such as strings or images, or for other model objects (i.e., drill down into the model).

An example: Let's say you have a Person objects in an array controller, and each Person has a name. You bind a table column to the array controller, controller key arrangedObjects (thereby getting the model objects), model key path name (thereby getting the value objects).

A more complex example: Suppose you have an array controller of Departments. Each Department contains Persons (employees in the department). You can bind your People array controller to the Departments controller, controller key arrangedObjects (getting the Department model objects), model key path @distinctUnionOfObjects.employees (getting the Person model objects), and then bind a table column to the People controller, controller key arrangedObjects, model key path name.

That table would be for people who work for your company; if you have a separate table of prospective employees, you can create Person objects for them, too, and they won't show up in the table of existing employees because they're not in a Department. When you hire them, you'll add them to one or more Departments; then, they'll show up in the People array controller automatically, because that array controller is observing the employees of all of the Departments.

烟柳画桥 2024-07-21 10:50:54

控制器键弹出菜单可以帮助您发现控制器(通常是 NSArrayController、NSObjectController 或 NSTreeController)呈现的键。

最好的例子是 NSArrayControllers 的 selection 键,它包含一组选定的对象。 令人困惑的是 NSObjectController 也提供了一个“选择”键,尽管控制器只能控制单个对象(因此选择 = 对象)。

我同意这根本不清楚。 当我以编程方式绑定对象时(即使用 bind:toObject:withKeyPath:options: 方法),我个人开始理解它。

The Controller Key pop-up menu is a way to help you discover what keys the controller (typically a NSArrayController, NSObjectController or a NSTreeController) presents.

The best example is the selection key of NSArrayControllers, which contains the set of selected objects. What is confusing is the NSObjectController presents a 'selection' key too, although the controller can control only a single object (therefore the selection = the object).

I agree that it is not clear at all. I personnally began to understand it when I bound my objects programmatically (i.e. using the bind:toObject:withKeyPath:options: method).

于我来说 2024-07-21 10:50:54

它与键值编码有关。 您可以将 IB 中的控件绑定到控制器中的值。 要连接该值,您必须指定它的键路径。 例如,如果 IB 中有一个文本字段,并且想要将其绑定到控制器中名为“name”的字段,则可以将“name”指定为键路径。 然后,您需要在控制器中设置名称字段,以便可以通过键值编码进行访问。 这是在 10.5 中通过使用 @property 和 @synthesize 说明符完成的。

It has to do with key-value coding. You can bind a control in IB to a value in your controller. To connect that value, you have to specify the keypath to it. For example, if you have a textfield in IB and you want to bind it to say a field called 'name' in your controller, you would specify 'name' as the keypath. You then need to set up your name field in your controller to be accessible through key-value coding. This is done in 10.5 by using the @property and @synthesize specifiers.

百善笑为先 2024-07-21 10:50:54

看看这个主题:Cocoa 键值绑定:控制器键的各种选项的解释是什么?

我发布了在哪里可以找到所有控制器键的定义的解释。

Take a look at this topic: Cocoa Key Value Bindings: What are the explanations of the various options for Controller Key?

I posted an explanation of where to find definitions for all Controller Key's there.

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