Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there really no way to capture the backspace character?

Tags:

objective-c

Objective-C is said to accept "\b" as the special character for backspace, how can I capture this in program?

My purpose is to catch it in an if-statement to enable me screen characters for my textField:

if ([someCharacter isEqualToString:@"\b"]) { }

like image 915
user265961 Avatar asked Feb 05 '10 07:02

user265961


1 Answers

I decided to forget to capture the backspace character itself, I programmatically captured the state by comparing the lengths of the string before and after the character placing action of the textField:shouldChangeCharactersInRange:replacementString: method. This is the code:

if  ([[textField1.text stringByReplacingCharactersInRange:range withString:string] length] < textField1.text.length)
{
    //do nothing
}
else
{
    //more programme code;
}
like image 153
user265961 Avatar answered Oct 18 '22 05:10

user265961