Hello,
I having a hard time to capture the backspace button in a UITextView. I am trying to capture it in the method
- (BOOL)textView:(UITextView *)textView
shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
I thought it was ok to do like this.
if([text isEqualToString:@"\b") { // code ... }
But for some reason, when backspace is pressed 'text' is empty.
I know I can compare lenght of the UITextView but it isnt what I want to achieve.
So I found a solution to this.
If I look at '[text lenght]' every key on the defaultkeyboard returns >0 . Every key excepts the backspace wich is 0. In that way i know when backspace is pressed.
I do this check.
if([text lenght] == 0) { // BACKSPACE PRESSED }
What is your opinion about this? -or can I do it in a better way?
EDIT: As David Gelhar told me, this wont work cus CUT will trigger ([text lenght] == 0) aswell.
Anyone that can point me to the correct directions here?
Regards. - Martin