I am using number pad for my UITextField's
.
I have set the delegate for my textfields.
I used the required delegate
methods to handle the different events.
But I am unable to capture the event when user taps on x
mark on number pad when a textfield
hasBecomeFirstResponder
and there are no characters entered in a textfield
.
However, I can get the delete event when user pressed any character(or when there is atleast one character present in the textfield) and then press on delete key.
I set the keypad type as number pad in storyboard
.
Delegate is set in both storyboard and also in code.
Here is the code if you want to have a look:
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
if ([string length]==0) {
NSLog(@"deleted");
return YES;
}
}
I think the above method should get hit whenever the I press any key on keyboard. But in my case, this method is not hit when I press the delete key when the textfield is empty.
My question is: I am looking for a way to detect press on delete key in an efficient way. I don't want to add a button on top of the delete button. As one answer suggested to add a button to the delete key.
Is it possible to add the target method to the delete key,so that whenever I press delete key, that method would get hit? (Or) Is is possible to get a delete key event when there are no characters in a textfield and when the textfield has become the first responder?
I want to know because, I have four textfields placed in a horizontal stack view. When the user enters one character in first textfield, I am making the second text field as first responder,and the user enters the text on second textfield.
And the same way, I want to make the other textfield become first responder, when the user press delete key.Please note that, when I want to move back to other textfield by pressing the delete key, there will be no characters entered in the current textfield.And I am unable to detect delete key event when the textfield is empty.