Ilya Suzdalnitski
Ilya Suzdalnitski

Reputation: 53540

Is UITextField empty?

To know if an UITextField is empty I used the following code:

if ( [ [textField text] isEqualToString:@""] )

But unfortunately it somehow fails to tell if the text field is empty.

What are the other ways?

When [textField text] is empty, it equals to nil.

Thank you.

Upvotes: 1

Views: 4160

Answers (2)

Koraktor
Koraktor

Reputation: 42913

[textField hasText]

See reference.

Upvotes: 7

Sophie Alpert
Sophie Alpert

Reputation: 143134

Perhaps try [[textField text] length] == 0?

Upvotes: 12

Related Questions