0

代码在这里:

[self.textView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

观察法

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSLog(@"change %@", change);
}

每次我在 textView 中输入单词时,即使 contentSize 没有变化,该方法也会被调用。 而且iOS7没有问题。

什么可能导致这个问题?这是 UIKit 中的错误吗?

4

1 回答 1

0

尝试这个,

[self.textView addObserver:self forKeyPath:@"contentSize" options:(NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew) context:@"mycontext"];  

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    NSString *oldValue = [change objectForKey:NSKeyValueChangeOldKey];
    NSString *newValue = [change objectForKey:NSKeyValueChangeNewKey];

    NSLog(@"OldValue %@",oldValue);
    NSLog(@"NewValue %@",newValue);
}
于 2013-10-21T12:35:41.200 回答