2

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?

user3781236
  • 728
  • 2
  • 9
  • 23
  • FYI - I'm using similar code to detect content size changes for `UITextView` and it is still working just fine for me under iOS 9. But I'm passing `0` for the options. – rmaddy Sep 10 '15 at 22:03
  • good to know - thanks! for the record, using the below suggestion and subclassing UITextView has it working again and feels much more reliable! – user3781236 Sep 10 '15 at 22:10

1 Answers1

2

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.

Community
  • 1
  • 1
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222