How to detect when UITextField become empty

Posted by Jakub on Stack Overflow See other posts from Stack Overflow or by Jakub
Published on 2010-05-08T17:35:16Z Indexed on 2010/05/08 17:38 UTC
Read the original article Hit count: 268

Filed under:
|

Hello,

I would like to perform a certain action when UITextField becomes empty (user deletes everything one sign after another or uses the clear option).

I thought about using two methods

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;

and

- (BOOL)textFieldShouldClear:(UITextField *)textField;

from

UITextFieldDelegate

I'm not sure how to detect the situation when the text field becomes empty? I tried with:

if ([textField.text length] == 0)

but it does't work as the fisrt of the above methods is called before the sign is deleted from the text field.

Any ideas?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk