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