Post

Replies

Boosts

Views

Activity

Reply to shouldChangeCharactersIn called twice on simulator
I've found a workaround to this extra backspace character in 'shouldChangeCharactersIn' delegate. Keep in mind, this issue also affects the UITextViewDelegate method as well. The workaround is to return false from the method and just perform the manipulation of the text in there manually. Using this API, you can just get the output of the call and assign to self.text. You will no longer see the extra call to 'shouldChangeCharactersIn' but you have to make the update to the text yourself by returning false. Hope this helps! Objective-C example: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString * textBeforeChange = textField.text; NSString * textAfterChange = [textBeforeChange stringByReplacingCharactersInRange:range withString:string]; [textField setText:textAfterChange]; return NO; }
Mar ’24