observeValueForKeyPath 未调用
我正在使用观察者遵循代码
myView = [[UIView alloc] initWithFrame:CGRectZero];
[myView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
另一个代码
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"observeValueForKeyPath");
if([keyPath isEqualToString:@"frame"])
{
[self layoutViews];
}
}
,但我从未得到日志observeValueForKeyPath
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIKit 并不始终符合 KVO,并且您不应该想当然地认为 UIKit 类上的属性永远符合 KVO,即使它们似乎是通过实验实现的。
另请参阅:iOS:我如何知道是否属性是否符合 KVO 标准?
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?