observeValueForKeyPath not calling

1.3k views Asked by At

I am using observer following code

myView = [[UIView alloc] initWithFrame:CGRectZero];
[myView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];

Another Code

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"observeValueForKeyPath");
    if([keyPath isEqualToString:@"frame"]) 
    {
        [self layoutViews];
    }
}

but I never got the Log observeValueForKeyPath

1

There are 1 answers

0
Joshua Pokotilow On

UIKit isn't consistently KVO-compliant, and you shouldn't take it for granted that properties on UIKit classes are ever KVO-compliant, even if they seem to be through experimentation.

See also: iOS: How do I know if a property is KVO-compliant?