首先,處理文字字數(shù)限制問題,應該從兩個方面入手,鍵盤輸入和面板輸入
1、- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
? ? ? ? ? ?從鍵盤輸入的文本插入的時候,喚醒 ?shouldChangeTextInRange,有助于提前禁止從鍵盤輸入!
2、- (void)textViewDidChange:(UITextView *)textView
從鍵盤的備選面板輸入的時候,只會直接觸發(fā) textViewDidChange,不同于鍵盤輸入觸發(fā)shouldChangeTextInRange
因此,在 textViewDidChange 中,依然很有必要要對 UITextView ?的字數(shù)限制!
附:- (NSString *)substringToIndex:(NSUInteger)anIndex
提取從 0 到? anIndex之間的字符串,不包括 anIndex , contain up to anIndex ,but not include