Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

observeValueForKeyPath not calling

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

like image 824
Amit Battan Avatar asked Feb 25 '26 06:02

Amit Battan


1 Answers

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?

like image 167
Joshua Pokotilow Avatar answered Feb 28 '26 00:02

Joshua Pokotilow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!