observeValueForKeyPath not being called

Antonio picture Antonio · Apr 28, 2010 · Viewed 8.3k times · Source

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 logoAnimation.patrocinioDidLoad has changed, observeValueForKeyPath never gets called...

Am I missing something?

Thanks for the help!

Antonio

Answer

Antonio picture Antonio · Apr 28, 2010

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!