UIButton状态的键值观察 [英] Key-value observing on UIButton's State
问题描述
UIButton有一个州财产,所有帐户似乎都符合KVO标准,没有其他说明文件。但是,当我向UIButton的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?
推荐答案
如果查看UIControl的文档,则会将state属性标记为:来自其他旗帜。
If you look at the documentation of UIControl, the state property is marked: synthesized from other flags.
我想这就是为什么这个属性的更改不符合KVO。
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.
These properties are KVO compliant and you will get the observer callback when they change.
这篇关于UIButton状态的键值观察的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!