Question

I have three text fields, lets name them:

  1. textField1.
  2. textField2
  3. textField3

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?

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top