IOS development Note 12: The ios7uitextfield crashes due to the limited number of words entered in UITextField on iOS7.
In some scenarios, You need to limit the number of words you enter, for example, control in textField (textView is similar, and the cause of the crash is the same ),
The input under will also listen. If not processed, it will easily crash. For example, when the limit on the number of words is reached, the input will continue. In this case, textField. text = Lenovo input text + textField existing text, when textField. when the text limit is exceeded, the part with the limit length is intercepted and assigned to textField. text, but the input data is not submitted yet, textField. text cannot be changed, so conflicts are generated, resulting in crashes. When iOS8 and 9 do not crash, it is estimated that the system has optimized the processing. When the number of words reaches the limit, Lenovo text within the limit is automatically entered into textField.
The solution is to check whether markedTextRange is nil, that is, when there is no Lenovo or highlighted text, check the text limit length or assign a value.
Refer:TextViewDidChange: crashes in iOS 7