Cocoa Key Value Bindings:Controller Key的各个选项的解释是什么?
当我使用 Interface Builder 将控件绑定到 NSArrayController 时,绑定检查器中的“Controller Key”字段下有多种选项。
我理解什么是“arrangedObjects”,我半理解什么是“选择”,但我很想看到对所有选项以及何时使用每个选项的非常好的解释。该列表包括:selectionIndexes、selectionIndex、selectedObject、sortDescriptors 等。我还没有找到这些选项的很好的解释。
我在使用绑定到目标 > 的按钮时遇到问题选择,所以我希望对这些控制器键有更深入的了解可以帮助我调试我的问题。
谢谢!!!
When I bind a control to an NSArrayController using Interface Builder, there are a variety of options under the "Controller Key" field in the bindings inspector.
I understand what "arrangedObjects" is, and I semi-understand what "selection" is, but I'd love to see a really nice explanation of all the options and when to use each one. The list includes: selectionIndexes, selectionIndex, selectedObject, sortDescriptors, etc. I haven't been able to find a good explanation of these options.
I'm having trouble with a button that's bound to target > selection, so I'm hoping a much deeper understanding of these Controller Keys might help me debug my issue.
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这些很难找到。各种 Cocoa 书籍,甚至 Apple 的文档似乎到处都引用了它们,但我还没有看到有人将它们的解释统一到一个位置。答案是,Apple 在每个控制器类的文档中定义了它们:
这些文档也很有用:
这些“Controller”对象的继承看起来像这样(这对于发现某些“Controller Key”选项的来源很重要):
如果您找到特定类的文档中未定义的控制器键,它可能在其超类中定义。下面是适用于上述各项的所有控制器键(Xcode 3.2.1、Interface Builder 3.2.1):
因此,在列表中找到您想要的控制器键,在文档中查找该控制器类,您会发现它的定义。如果它不存在,则可能是在其超类(可能是 NSObjectController)的文档中定义的。
These are tricky to find. They seem to be referenced everywhere by various Cocoa books, and even Apple's docs, but I haven't seen anyone unify an explanation of them into a single location. The answer is, Apple defines them inside the docs for each controller class:
These docs are also useful:
Inheritance for these "Controller" objects looks like so (this is important to discover where some of the "Controller Key" options come from):
If you find a Controller Key not defined in the docs for a particular class, it's probably defined in its superclass. Below are all the Controller Keys available for each of the above (Xcode 3.2.1, Interface Builder 3.2.1):
So, find the one on the list you want, look in the docs for that controller class, and you'll find its definition. If it's not there, it's probably defined in the docs for its superclass (likely NSObjectController).
控制器键是您要绑定的(控制器对象的属性)的键。模型关键路径是绑定对象可以向模型对象询问更基本的对象(例如字符串或图像)或其他模型对象(即深入模型)的关键路径。
示例:假设数组控制器中有一个 Person 对象,每个 Person 都有一个
名称
。您将表列绑定到数组控制器、控制器键arrangedObjects
(从而获取模型对象)、模型键路径name
(从而获取值对象)。一个更复杂的示例:假设您有一个 Departments 数组控制器。每个部门都包含人员(部门中的员工)。您可以将 People 数组控制器绑定到 Departments 控制器、控制器键
arrangedObjects
(获取 Department 模型对象)、模型键路径@distinctUnionOfObjects.employees
(获取 Person 模型对象) ),然后将表列绑定到 People 控制器、控制器键arrangedObjects
、模型键路径name
。这张桌子是为你公司的员工准备的;如果您有一个单独的潜在员工表,您也可以为他们创建 Person 对象,并且他们不会显示在现有员工的表中,因为他们不在部门中。当您雇用他们时,您会将他们添加到一个或多个部门;然后,他们将自动显示在人员数组控制器中,因为该数组控制器正在观察所有部门的
员工
。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 keyarrangedObjects
(thereby getting the model objects), model key pathname
(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 keyarrangedObjects
, model key pathname
.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.您需要 Cocoa 绑定参考。
You want the Cocoa Bindings Reference.
查看Interface Builder 用户指南< /a>,有一个“连接和绑定”部分,其中有表 7-1,其中内容如下:
Have a look at the Interface Builder User Guide, there is a section "Connection and Bindings" with a table 7-1 in which it reads: