Reputation: 1373
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"]) { }
Upvotes: 6
Views: 1009
Reputation: 1373
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;
}
Upvotes: 2