关于UITextView的textViewDidChange回调没有调用的问题解决


最近在做一个需求的时候,出现了这样一个问题:textViewDidChange当程序中给UITextView赋值的时候,是不被调用的,如官方文档对该方法的说明:

Tells the delegate that the text or attributes in the specified text view were changed by the user.
The text view calls this method in response to user-initiated changes to the text. This method is not called in response to programmatically initiated changes.

如果必要在程序中给UITextView赋值又希望有相应的动作的话,我采用了一个替代方案:

1.在合适的地方注册一个系统的通知(注意name,系统定义的):

       [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChangedExt:) name:UITextViewTextDidChangeNotification object:nil];

2.实现textChangedExt:

- (void)textChangedExt:(NSNotification *)notification

{

 //todo sth...

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM