Detect backspace in UITextField
- by marcc
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.