KVO notifications with textView.text

923 views Asked by At

I need notifications with textView.text, but the do not work.

My code:

Add a KVO:

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

Observing method

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

I am trying change contentSize. KVO is working...

1

There are 1 answers

1
Reming Hsu On BEST ANSWER

https://developer.apple.com/library/ios/documentation/General/Conceptual/DevPedia-CocoaCore/KVO.html

Note: Although the classes of the UIKit framework generally do not support KVO, you can still implement it in the custom objects of your application, including custom views.

There have another way to help you simply.

  • Conform UITextViewDelegate protocol methods.

  • Use method - (void)textViewDidChange:(UITextView *)textView; to get textView.text changed.