views:

224

answers:

2

Hi,

To know if an UITextView 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.

+2  A: 

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

Ben Alpert
Thank you, this works for me.
Ilya
This works even if [textField text] is nil, since in Objective-C you always get 0 returned from a nil object.
Chris Lundie
+2  A: 
[textField hasText]

See reference.

Koraktor
What you are pointing me to is UITextView. And UITextField doesn't have this method. Unfortunately.
Ilya
I already wondered why you named your variable textField while referencing to UITextView in the question title.
Koraktor