IOS checks whether uitextfield. Text is null

Source: Internet
Author: User

Determining that the nsstring is null is a problem that almost every developer will encounter. The following method is the first thing that most people flash their brains.

If ([yourtextstring isequaltostring: @ ""])

However, it is a pity that such judgments often fail, resulting in many inexplicable bugs. For example, if you use this method to determine whether uitextfield is empty, a problem may occur.

[Yourtextfield. Text isw.tostring: @ ""]

The above line will also be "no" if the user does not make any input. What is the reason?

The answer is actually very simple. The value of yourtextfield. text after initial creation is nil, and nil is not equal to @ ", so the above Code should be changed:

[Yourtextfield. Text is1_tostring: @ ""] | yourtextfield. Text = Nil

Although the above line of code can work normally, it is a bit depressing to write such a line of code every time. In fact, there is a simple and clear work ing method that I suggest you use:

Yourtextfield. Text. Length = 0

Address: http://www.cnblogs.com/hellocby/archive/2012/12/20/2826318.html

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.