原因分析:最近测试发现在某个页面的UITextView输入中文时,会显示输入错乱,如上图所示。语言问题,输入法等可能因素后,锁定了问题的所在: 为了实现字数限制 和禁止输入换行符,我在回调函数里写了如下的坑爹代码:
-(void)textViewDidChange:(UITextView *)textView
{
textView.text = [textView.text stringByReplacingOccurrencesOfString:@"\n" withString:@""];
NSUInteger len = MIN([textView.text length],140);
textView.text = [textView.text substringToIndex:len];
countLabel.text = len>0?[NSString stringWithFormat:@"还可输入%d字",140-len]: