How to limit the number of words in textview

Source: Internet
Author: User

 

The method used at the beginning is the function textview: shouldchangetextinrange: replacementtext: To judge:

// When you type done, insert a line break and execute addbookmark <br/>-(bool) textview :( uitextview *) textview <br/> shouldchangetextinrange :( nsange) range <br/> replacementtext :( nsstring *) text <br/> {<br/> // you can specify the input character in the range, whether the limit is exceeded <br/> nsstring * STR = [nsstring stringwithformat: @ "% @", textview. text, text]; <br/> If (Str. length> bookmark_word_limit) <br/>{< br/> textview. TEXT = [textview. text substringtoindex: bookmark_word_limit]; <br/> return no; <br/>}< br/> return yes; <br/>} 

 

However, it is found that this method cannot be used to judge the words entered by Lenovo when there is a Lenovo input, and then textviewdidchange: is used to verify the feasibility:

 

/* Due to Lenovo input, the function textview: shouldchangetextinrange: replacementtext: the number of words cannot be determined, <br/> Use textviewdidchange to determine the number of words in textview <br/> */<br/>-(void) textviewdidchange :( uitextview *) textview <br/>{< br/> // this judgment is used for Lenovo input <br/> If (textview. text. length> bookmark_word_limit) <br/>{< br/> textview. TEXT = [textview. text substringtoindex: bookmark_word_limit]; <br/>}< br/>} 

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.