Detect backspace in UITextField

Posted by marcc on Stack Overflow See other posts from Stack Overflow or by marcc
Published on 2009-12-30T01:21:17Z Indexed on 2010/04/16 16:03 UTC
Read the original article Hit count: 595

Filed under:
|

Is there any way to detect when the backspace/delete key is pressed in the iPhone keyboard on a UITextField that is empty? I want to know when backspace is pressed only if the UITextField is empty.


Based on the suggestion from @Alex Reynolds in a comment, I've added the following code while creating my text field:

[[NSNotificationCenter defaultCenter] addObserver:self
          selector:@selector(handleTextFieldChanged:)
              name:UITextFieldTextDidChangeNotification
            object:searchTextField];

This notification is received (handleTextFieldChanged function is called), but still not when I press the backspace key in an empty field. Any ideas?


There seems to be some confusion around this question. I want to receive a notification when the backspace key is pressed. That's it. But the solution must also work when the UITextField is already empty.

© Stack Overflow or respective owner

Related posts about uitextfield

Related posts about iphone