Cocoa Key Value Bindings:Controller Key的各个选项的解释是什么?

发布于 2024-08-11 23:46:51 字数 331 浏览 9 评论 0原文

当我使用 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 技术交流群。

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

发布评论

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

评论(4

撩起发的微风 2024-08-18 23:46:51

这些很难找到。各种 Cocoa 书籍,甚至 Apple 的文档似乎到处都引用了它们,但我还没有看到有人将它们的解释统一到一个位置。答案是,Apple 在每个控制器类的文档中定义了它们:

  • NSObjectController (doc)
  • NSArrayController (doc)
  • NSDictionaryController (doc)
  • NSTreeController (doc)
  • NSUserDefaultsController (doc

这些文档也很有用:

这些“Controller”对象的继承看起来像这样(这对于发现某些“Controller Key”选项的来源很重要):

NSController -> NSObjectController
NSController -> NSObjectController -> NSArrayController
NSController -> NSObjectController -> NSArrayController -> NSDictionaryController
NSController -> NSObjectController -> NSTreeController
NSController -> NSUserDefaultsController

// Note:  NSController is an abstract class (don't worry about it).  It inherits from NSObject.

如果您找到特定类的文档中未定义的控制器键,它可能在其超类中定义。下面是适用于上述各项的所有控制器键(Xcode 3.2.1、Interface Builder 3.2.1):

// **NSObjectController**
canAdd
canRemove
isEditable
selectedObjects
selection


// **NSArrayController**
arrangedObjects
canAdd
canInsert
canRemove
canSelectNext
canSelectPrevious
filterPredicate
isEditable
selectedObjects
selection
selectionIndex
selectionIndexes
sortDescriptors


// **NSDictionaryController**
arrangedObjects
canAdd
canInsert
canRemove
canSelectNext
canSelectPrevious
filterPredicate
isEditable
selectedObjects
selection
selectionIndex
selectionIndexes
sortDescriptors


// **NSTreeController**
arrangedObjects
canAdd
canAddChild
canInsert
canInsertChild
canRemove
isEditable
selectedObjects
selectedNodes
selection
selectionIndexPath
selectionIndexPaths
sortDescriptors


// **NSUserDefaultsController**
hasUnappliedChanges
values

因此,在列表中找到您想要的控制器键,在文档中查找该控制器类,您会发现它的定义。如果它不存在,则可能是在其超类(可能是 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:

  • NSObjectController (doc)
  • NSArrayController (doc)
  • NSDictionaryController (doc)
  • NSTreeController (doc)
  • NSUserDefaultsController (doc)

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):

NSController -> NSObjectController
NSController -> NSObjectController -> NSArrayController
NSController -> NSObjectController -> NSArrayController -> NSDictionaryController
NSController -> NSObjectController -> NSTreeController
NSController -> NSUserDefaultsController

// Note:  NSController is an abstract class (don't worry about it).  It inherits from NSObject.

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):

// **NSObjectController**
canAdd
canRemove
isEditable
selectedObjects
selection


// **NSArrayController**
arrangedObjects
canAdd
canInsert
canRemove
canSelectNext
canSelectPrevious
filterPredicate
isEditable
selectedObjects
selection
selectionIndex
selectionIndexes
sortDescriptors


// **NSDictionaryController**
arrangedObjects
canAdd
canInsert
canRemove
canSelectNext
canSelectPrevious
filterPredicate
isEditable
selectedObjects
selection
selectionIndex
selectionIndexes
sortDescriptors


// **NSTreeController**
arrangedObjects
canAdd
canAddChild
canInsert
canInsertChild
canRemove
isEditable
selectedObjects
selectedNodes
selection
selectionIndexPath
selectionIndexPaths
sortDescriptors


// **NSUserDefaultsController**
hasUnappliedChanges
values

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).

念三年u 2024-08-18 23:46:51

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

示例:假设数组控制器中有一个 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 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-08-18 23:46:51

查看Interface Builder 用户指南< /a>,有一个“连接和绑定”部分,其中有表 7-1,其中内容如下:

控制器键:控制器的一个属性
NSController 对象。当绑定到
一个 NSController 对象,你可以使用它
字段来选择第一个条目
关键路径。关联的菜单
该字段显示属性
在所选控制器上可用
对象作为一种方便。您可以输入
财产的名称或简单地
从提供的列表中选择它。

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:

Controller Key: An attribute of an
NSController object. When binding to
an NSController object, you use this
field to select the first entry in the
key path. The menu associated with
this field displays the properties
available on the selected controller
object as a convenience. You can type
the name of the property or simply
select it from the provided list.

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