将 NSTextField 的启用属性绑定到 setter 的存在吗?
我正在制作一张旨在编辑对象的工作表,该对象的类可以是实现协议“服务器”的任何对象。 URL 的 setter 方法是可选的,因为某些类型的终端节点(例如 Amazon S3)具有固定的 URL。
我想知道的是:是否可以将 NSTextField 的“Enabled”属性绑定到这些方法的存在?或者我是否还必须实现一个 BOOL 方法来返回该类是否支持编辑 URL?
非常感谢任何建议!
比利
I'm working on a sheet designed to edit an object who's class could be anything that implementes the protocol "Server". The setter methods for the URL are optional, since some types of endpoints, like Amazon S3, have a fixed URL.
What I'm wondering is: is it possible to bind the "Enabled" property of an NSTextField to the existence of those methods? Or do I have to also implement a BOOL method that returns whether or not the class supports editing the URL?
Any advice is greatly appreciated!
Billy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cocoa 绑定依赖于键值编码和键值观察。为了绑定 NSTextField 的“Enabled”属性,您需要绑定到符合 KVC 的属性: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Compliant.html
这意味着您将需要为您的服务器类实现 canEditURL 属性。
您可以在基类中实现它,如下所示:
Cocoa bindings rely on key-value coding and key-value observing. In order to bind the "Enabled" property of an NSTextField, you need to bind to a KVC compliant property: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/Compliant.html
This means you'll need to implement a canEditURL property for your server classes.
You could implement it in a base class as follows though: