Thank you @Claude31 for quick response. I am not on my office system currently, so I cannot show you code. What I can tell you is that on line 311, cursor position is set to using selectedTextRange property. Code is written in Objective C. Can it somehow call shouldChangeCharactersInRange again? I am unable to reproduce crash.
Post
Replies
Boosts
Views
Activity
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;
}
Sorry, my bad. I forgot to add the chunk. Please find it in the previous reply.