How to detect UIKeyboard "backspace" button touch on UITextField?

elp picture elp · Jul 25, 2011 · Viewed 24.7k times · Source

How can i detect backspace button pressed on UIKeyboard?

enter image description here

thanks


EDIT: Is there any keyboard delegate that returns key pressed value?

Answer

LombaX picture LombaX · Oct 13, 2012

if the UITextField is empty, the shouldChangeTextInRange delegate method is not called You can subclass UITextField and override this method:

-(void)deleteBackward;
{
    [super deleteBackward];
    NSLog(@"BackSpace Detected");
}

since UITextField is compliant to the UITextInput protocol, this method is implemented, and you can override it to detect when backspace is pressed. Then, you can write your own protocol/delegate method to alert your custom textfield delegate if the backspace is detected.