开发者

observeValueForKeyPath not being called

开发者 https://www.devze.com 2022-12-28 05:47 出处:网络
I have a ViewController creating an instance of a UIView, and then I register an observer with the instance, such that

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);
}

But, although I have checked and double-checked that logoAn开发者_如何学编程imation.patrocinioDidLoad has changed, observeValueForKeyPath never gets called...

Am I missing something?

Thanks for the help!

Antonio


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

patrocinioDidLoad = YES;

didn't work, whereas

self.patrocinioDidLoad = YES;

did!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号