When I delete characters from a UITextField field one-by-one, the delegate method textField:shouldChangeCharactersInRange:replacementString: is called.
When I type a full line of characters into a textfield, and then hold down the delete key, however iOS at first calls the delegate for each character it deletes. But at some point (about half way through the line) it just deletes everything that remains. The strange thing is that textField:shouldChangeCharactersInRange:replacementString: is not called when this happens. Neither is textFieldShouldClear:.
How can I detect this event? I want to update UI when the textfield is empty. And if I empty it in this fashion, my code fails to detect.
You can register an object to observe UITextFieldDidChangeNotification on your text field.
For example:
then
if you set a breakpoint on
You will see that it is called right before the last deletion occurs that sets the text field’s text property to nil.
You could also simply access your property self.textField, but I am demonstrating how to access the object the notification references. If you leave out the last parameter (object:) in -addObserver:selector:name:object: it will call the notification for all textFields in that object’s instance.