[英]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. UIButton有一个州财产,所有账户似乎都符合KVO标准,没有其他文件说明。 However, when I added an observer to a UIButton's state property, the observer callback was never invoked.
但是,当我向UIButton的state属性添加一个观察者时,从未调用过观察者回调。 How come?
怎么会?
If you look at the documentation of UIControl, the state property is marked: synthesized from other flags.
如果查看UIControl的文档,则会标记state属性:
synthesized from other flags.
I guess this is why changes to this property are not KVO compliant. 我想这就是为什么对这个属性的更改不符合KVO的原因。
However, you can simply register and observer for the values you need - highlighted, selected, enabled.
但是,您只需注册和观察您需要的值 -
highlighted, selected, enabled.
These properties are KVO compliant and you will get the observer callback when they change. 这些属性符合KVO,当它们发生变化时,您将获得观察者回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.