Search code examples
iosobjective-ckey-value-observingios9

iOS 9: KVO no longer working


I have an observer on a UITextView to detect if its content size is changing:

[_textView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:NULL];

This code always worked to call the following function, where I do resizing of the UITextView:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

However, in iOS 9, this function is never getting called. What changed in iOS 9 and how do I fix this?


Solution

  • If you do a search for UIKit and KVO Compliance you will see that everyone says you can't rely on it. See this question and this question.

    I don't know what changed, but I think you should just subclass UITextView and overload setContentSize: if you want to know when it changes.