observeValueForKeyPath未被调用 [英] observeValueForKeyPath not being called

查看:635
本文介绍了observeValueForKeyPath未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ViewController创建一个UIView的实例,然后我用实例注册一个观察者,这样

I have a ViewController creating an instance of a UIView, and then I register an observer with the instance, such that

logoAnimation = [[MainLogoAnimation alloc] init];
[logoAnimation addObserver:self forKeyPath:@"patrocinioDidLoad" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];

然后,在同一个文件中,我有:

then, in the same file, I have:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
 NSLog(@"%@ \n %@ \n %@ \n ",keyPath,object,change);
}

但是,虽然我已经检查并仔细检查过logoAnimation.patrocinioDidLoad已更改,observeValueForKeyPath永远不会被调用...

But, although I have checked and double-checked that logoAnimation.patrocinioDidLoad has changed, observeValueForKeyPath never gets called...

我错过了什么吗?

感谢您的帮助!

安东尼奥

推荐答案

解决它:
我正在设置patrocinioDidLoad直接在logoAnimation中,不使用标准的getter和setter。在logoAnimation中,

Solved it: I was setting patrocinioDidLoad in logoAnimation directly, without using standard getters and setters. In logoAnimation,

patrocinioDidLoad = YES;

不起作用,而

self.patrocinioDidLoad = YES;

do!

这篇关于observeValueForKeyPath未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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