Key-value observing on UIButton's State
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.
精彩评论