Post

Replies

Boosts

Views

Activity

Reply to UITextfield crash in iOS 13 using textField:shouldChangeCharactersInRange:replacementString
Crashlytics has pointed out line 311, that's why I mentioned. I have checked other crashes as well, and I can confirm line number mentioned points out to the correct LOC producing crash.MyTextField.m - Line 311-[MyTextField textField:shouldChangeCharactersInRange:replacementString:] + 311Well here is the code for function:- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *updatedString = [textField.text stringByReplacingCharactersInRange:range withString:string]; if (![StringUtils isEmptyOrNull:string] && _maxLength && updatedString.length > _maxLength) return NO; UITextPosition *initialCursorPostition = [self getInitialPostitionOfCursorWithRange:range andString:string]; textField.text = updatedString; [self moveCursorToPosition:initialCursorPostition]; //Line 311 in the code [self setHiddenClearButtonWithText:updatedString]; if (_textFieldDelegate && [_textFieldDelegate respondsToSelector:@selector(textField:shouldChangeCharactersInRange:replacementString:)]) { return [_textFieldDelegate textField:textField shouldChangeCharactersInRange:range replacementString:string]; } return NO; } -(void)moveCursorToPosition:(UITextPosition*)position { if(position) [self setSelectedTextRange:[self textRangeFromPosition:position toPosition:position]]; } -(UITextPosition*)getInitialPostitionOfCursorWithRange:(NSRange)range andString:(NSString*)string { UITextPosition *beginning = self.beginningOfDocument; UITextPosition *cursorLocation = [self positionFromPosition:beginning offset:(range.location + string.length)]; return cursorLocation; }
Mar ’20