开发者

How Do I Bind a UIButton Property to Another Property?

UIButton eventually inherits from NSObject, and NSObject implements NSKeyValueBindingCreation Protocol. So why can't I bind a UIButton's property to another class' property?

[myUIButton bind:@"enabled开发者_如何转开发"
        toObject:myOtherObject
     withKeyPath:@"otherObjectBOOLProperty"
         options:nil];

This results in the warning

'UIButton' may not respond to '-bind:toObject:withKeyPath:options:'

What I'm trying to do is bind the enabled state of my UIButton to myOtherObject.otherObjectBOOLProperty.


This is not so, iOS' NSObject does not conform to the NSKeyValueBindingCreation protocol.

I would use straight-up Key-Value Observing in your case.

See the Adopted Protocols of NSObject.


NSObject only conforms to NSObject protocol but you can use KVO to bind that:

Key-Value Observing Programming guide, Specially read how to register a property to be observed and how to receive notifications ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜