“控制器钥匙”的意义是什么? Inspector 中的 IB 属性 > 绑定窗格?

发布于 2024-07-14 03:47:45 字数 205 浏览 3 评论 0原文

苹果说:

NSController 对象的属性。 当绑定到 NSController 对象时,您可以使用此字段来选择键路径中的第一个条目。 为方便起见,与此字段关联的菜单显示所选控制器对象上可用的属性。 您可以键入属性的名称,或者直接从提供的列表中选择它。

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

Apple says:

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.

Can someone explain that in other words?

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

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

发布评论

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

评论(1

ペ泪落弦音 2024-07-21 03:47:45

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

myTextField.value <=> myModel.textValue.

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

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

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

You are binding a view object to a model property. Something like (schematically):

myTextField.value <=> myModel.textValue.

While you can bind a view property directly to your model object's property like shown above, you really shouldn't. You would miss out on the nice features provided by Apple's controllers (e.g. NSObjectController, NSArrayController, etc.). Instead you should bind your view to a controller which is bound to the model, like:

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

In this setup, myObjectController.selection is a Key-Value binding compatible proxy for myObjectController.contentObject and myObjectController can act as a mediator between the view and the model. Interface Builder makes this separation of concerns explicit because controllers may expose multiple proxies for their bound model (such as NSArrayController's arrangedObjects and selectedObjects). In binding myTextField.value in the example above, you would enter 'selection' in the "Controller Key" field and "textValue" in the "Model Object Keypath" path field.

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