“控制器钥匙”的意义是什么? Inspector 中的 IB 属性 > 绑定窗格?
苹果说:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在将视图对象绑定到模型属性。 类似于(示意性地):
虽然您可以将视图属性直接绑定到模型对象的属性,如上所示,但您确实不应该这样做。 您可能会错过 Apple 控制器提供的优秀功能(例如
NSObjectController
、NSArrayController
等)。 相反,您应该将视图绑定到与模型绑定的控制器,例如:在此设置中,myObjectController.selection 是 myObjectController.contentObject 的键值绑定兼容代理,并且 myObjectController 可以充当视图和模型之间的中介。 Interface Builder 使这种关注点分离变得明确,因为控制器可能会为其绑定模型公开多个代理(例如
NSArrayController
的arrangedObjects
和selectedObjects
)。 在上面示例中绑定 myTextField.value 时,您将在“控制器键”字段中输入“选择”,并在“模型对象键路径”路径字段中输入“textValue”。You are binding a view object to a model property. Something like (schematically):
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: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
'sarrangedObjects
andselectedObjects
). 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.