The best way to check if a text field has any text is to do:
if (textField2.text.length == 0) {
// no text
}
Question
I have three text fields, lets name them:
I want to write an if statement if the value (integer) of textField1 is changed to set textField2 and textField3 to equal 0 if they have no number entered within them.
Likewise with textField2 to change textField1 and textField3, etc.
I have tried to check if
textField2 = nil;
if textField2 = @""
Neither work!
How do I do so?
Solution
The best way to check if a text field has any text is to do:
if (textField2.text.length == 0) {
// no text
}
OTHER TIPS
Use textField.text
property to check the text in textField. You can use
if ([textField1.text length] == 0)
to check textfield is empty or not