Key-value observing on UIButton's State

这一生的挚爱 提交于 2019-12-22 04:29:29

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7544037/key-value-observing-on-uibuttons-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!