IOS development Note 12: The ios7uitextfield crashes due to the limited number of words entered in UITextField on iOS7.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.