iOS to determine if Uitextview is empty

Source: Internet
Author: User


It is almost every developer's problem to judge that NSString string is empty, and for most people the first thing to flash through the brain is the following method

if ([Yourtextstring isequaltostring:@ ""])

Unfortunately, such judgments often fail, causing many puzzling bugs, such as if using this method to determine whether Uitextfield is empty.

[Yourtextfield.text isequaltostring:@ "]

The above line generation will be no when the user does not make any input, which is why.

The answer is actually very simple, yourtextfield.text after the initial creation of the value of Nil,nil of course not equal to @ "", so the above code should read:

[Yourtextfield.text isequaltostring:@ "] | | Yourtextfield.text = = Nil

The above line of code, although it can work, but every time to write such a line of code, it is a bit depressing, in fact, there is a concise and clear method of adaptation, but also I suggest that you use:

YourTextField.text.length = 0

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.