Search code examples
objective-cnsmutablearraykey-value-observing

KVO. ObserveValueForKeyPAth is not called


I am not if this will work properly

[[cr1.crossRoad.trafficLights 
    objectForKey: [NSNumber numberWithInt:pedestrianTL]] 
    addObserver:view 
    forKeyPath:@"colorState" 
    options:NSKeyValueObservingOptionNew 
    context:nil];

The project I'm developing doesn't work properly. This way I was trying to add an observer to change the view with after every change happening to the cell of the colorState array.

-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
    [self refreshState:object];
}

The program never enters this method though I change values of the colorState cells. Maybe the problem is with me trying to observe array but not actually what it contains?


Solution

  • The problem was that I was trying to observe an array which was not possible that way.