關於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