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?

有帮助吗?

解决方案

The best way to check if a text field has any text is to do:

if (textField2.text.length == 0) {
    // no text
}

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top