cocoa - Inspector > Bindings Pane 中 IB 中的 "Controller Key"属性有什么意义?

标签 cocoa interface-builder cocoa-bindings

苹果说:

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.

有人可以换句话解释一下吗?

最佳答案

您正在将 View 对象绑定(bind)到模型属性。类似于(示意性地):

myTextField.value <=> myModel.textValue.

虽然您可以将 View 属性直接绑定(bind)到模型对象的属性(如上所示),但实际上不应该这样做。您可能会错过 Apple Controller 提供的优秀功能(例如 NSObjectControllerNSArrayController 等)。相反,您应该将 View 绑定(bind)到绑定(bind)到模型的 Controller ,例如:

myTextField.value <=> myObjectController.selection.textValue 
  and 
myObjectController.contentObject <=> myModel

在此设置中,myObjectController.selection 是 myObjectController.contentObject 的键值绑定(bind)兼容代理,并且 myObjectController 可以充当 View 和模型之间的中介。 Interface Builder 使这种关注点分离变得明确,因为 Controller 可能会为其绑定(bind)模型公开多个代理(例如 NSArrayControllerarrangedObjectsselectedObjects)。在上面示例中绑定(bind) myTextField.value 时,您将在“ Controller 键”字段中输入“选择”,并在“模型对象键路径”路径字段中输入“textValue”。

关于cocoa - Inspector > Bindings Pane 中 IB 中的 "Controller Key"属性有什么意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/596795/

相关文章:

objective-c - 制作一个具有开/关状态的自定义 NSButton,但仍处理 IBActions

cocoa - 如何在 Cocoa 的 Web View 中加载 nib/xib 文件?

swift - 我应该在 Swift 中使用 Cocoa 绑定(bind)吗?

cocoa - 使 nstextfield 单行

cocoa - 核心数据除以两个值

cocoa - 将数组 Controller 初始化从 nib 移动到代码会破坏 TableView 绑定(bind)

objective-c - OSX 应用程序中的 "Printing Not Allowed"

objective-c - 有没有办法运行两个或多个 NSTasks?

objective-c - Interface Builder 未正确调整大小

ios - Xcode - 如何修复 'NSUnknownKeyException' ,原因 : … this class is not key value coding-compliant for the key X"error?