开发者

Key-value observing on UIButton's State

开发者 https://www.devze.com 2023-04-08 10:14 出处:网络
UIButton has a state property, which appears to be KVO compliant by all accounts开发者_运维技巧 and there is no documentation to indicate otherwise.However, when I added an observer to a UIButton\'s s

UIButton has a state property, which appears to be KVO compliant by all accounts开发者_运维技巧 and there is no documentation to indicate otherwise. However, when I added an observer to a UIButton's state property, the observer callback was never invoked. How come?


If you look at the documentation of UIControl, the state property is marked: synthesized from other flags.

I guess this is why changes to this property are not KVO compliant.

However, you can simply register and observer for the values you need - highlighted, selected, enabled. These properties are KVO compliant and you will get the observer callback when they change.

0

精彩评论

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

关注公众号