textview.selectedRange.location in UITextview show 2147483647
- by Risma
hi
i have a textview and i want to get the selectedRange.location value from that textview.
in the first time when the keyboard appear, the location value always show an integer point such as 110, or others. But if i dissappear the keyboard and then appear the keyboard again, the location value always show 2147483647. What is this 2147483647 mean and how to get the real location value?
This is my code in the keyboard will appear method :
-(void)keyboardWillAppear:(NSNotification *)notification {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:[[[notification userInfo]
objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]];
CGRect keyboardEndingUncorrectedFrame = [[[notification userInfo]
objectForKey:UIKeyboardFrameEndUserInfoKey ] CGRectValue];
CGRect keyboardEndingFrame =
[self.view convertRect:keyboardEndingUncorrectedFrame
fromView:nil];
[UIView commitAnimations];
NSRange selectedRange = textview.selectedRange;
NSLog(@"selected Range location : %f", selectedRange.location);
}