Capture Backspace , is this a OK solution?
Posted
by f0rz
on Stack Overflow
See other posts from Stack Overflow
or by f0rz
Published on 2010-04-30T13:27:13Z
Indexed on
2010/04/30
13:37 UTC
Read the original article
Hit count: 393
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?
Regards. - Martin
© Stack Overflow or respective owner