是否可以观察Cocoa Touch中对象的readonly属性? [英] Is it possible to observe a readonly property of an object in Cocoa Touch?

查看:106
本文介绍了是否可以观察Cocoa Touch中对象的readonly属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图观察(readonly)一个UINavigationController的visibileViewController属性没有成功。我能够成功地观察一个readwrite属性,我为自己定义的测试目的在另一个类上。

I've attempted to observe the (readonly) visibileViewController property of a UINavigationController with no success. I was able to successfully observe a readwrite property I defined myself for testing purposes on another class.

是否可能观察者readonly属性?

Is it possible to observer readonly attributes?

推荐答案

是的,可以观察只读属性。但是,如果声明该属性的对象以不是键值观察符合 (例如,更改直接支持该属性的实例变量的值,而不会引起镇静 willChangeValueForKey: didChangeValueForKey:通知),则观察者不会自动通知KVO系统。如果你可以验证这个属性的值是否改变,并且你的观察者没有被通知,我会(1)在这里或其他地方发布一些代码,以便其他人可以帮助你找到你的错误和(2)如果没有错误您的代码,在Apple的雷达上提出错误。

Yes, it is possible to observe read-only properties. However, if the object that declares that property makes changes to the value of that property in a way that is not Key-Value Observing compliant (e.g. changes the value of the instance variable backing that property directly without seding willChangeValueForKey: and didChangeValueForKey: notifications) then observers will not automatically be notified by the KVO system. If you can verify that the value of this property is changing and your observers are not being notified, I would (1) post some code here or elsewhere so that others can help you find your bug and (2) if there is no bug in your code, file a bug on Apple's radar.

这篇关于是否可以观察Cocoa Touch中对象的readonly属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆