Evil Nodoer
Evil Nodoer

Reputation: 1957

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?

Upvotes: 10

Views: 6236

Answers (1)

adamsiton
adamsiton

Reputation: 3672

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.

Upvotes: 23

Related Questions