0
votes

I'm trying to determine when the keyboard's back button is pressed. When there is text in the text field, this is easy. I simply use the delegate method - (BOOL)textField:(UITextField *)aTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string. The problem is when the text field is empty and the back button is pressed, this method isn't called.

Does anyone know how to get notified even when the text field is empty?

3
Do you mean the delete/backspace key?jrturton
Yes. The delete backspace button.Quentamia

3 Answers

3
votes

Could you default in a single space to the empty field when you begin editing (and the field is empty) so that the backspace becomes a normal event? You could remove the space when leaving the field and/or the first normal character is typed. Bit of a hack but I don't think you'll get to it any other way.

-1
votes

Check out this answer..

Receive iPhone keyboard events

In your keyPressed function, check to see if the textfield value has any content;

-1
votes

In the delegate method:

(BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string

keep the earlier string and compare it with the string, if count of string is 1 less than the previous modified string it means delete is pressed. Otherwise store string into earlier string. hope this will help you.