本文主要是介绍iOS 报错:!!! _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index libc++abi.dylib: termi,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
出现的场景:
UITextView限制输入的字数
- (void)textViewDidChange:(UITextView *)textView
{
if (textView.text.length == 0) {_placeHolderLab.hidden = NO;
}else{_placeHolderLab.hidden = YES;
}if (textView.text.length >= 10) {NSString *str= [textView.text substringToIndex:10];textView.text = str;
}
}
复现场景:
当进入 if (textView.text.length >= 10) 判断就会崩溃,当然也不是什么机器都崩溃的,当时测试给出的机器是 iPhone4S 系统 7.1.0
自己测试 7以上的系统没有问题,并且在 iPhone4S 系统 7.1.0 的机器上输入纯英文,纯数字是没有问题的,只有输入中文才会崩溃。
解决办法:
- (void)textViewDidChange:(UITextView *)textView
{
if (textView.text.length == 0) {_placeHolderLab.hidden = NO;
}else{_placeHolderLab.hidden = YES;
}if (textView.text.length >= 10) {NSString *str= [textView.text substringToIndex:10];dispatch_async(dispatch_get_main_queue(), ^{textView.text = str;});
}
}
更新UI在主线程中更新
这篇关于iOS 报错:!!! _NSLayoutTreeLineFragmentRectForGlyphAtIndex invalid glyph index libc++abi.dylib: termi的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!