UITextview 中的 textview.selectedRange.location 显示 2147483647
我有一个文本视图,我想从该文本视图获取 selectedRange.location 值。 第一次出现键盘时,位置值总是显示整数点,例如110或其他。但是如果我消失键盘然后再次出现键盘,位置值总是显示2147483647。这个2147483647是什么意思以及如何获取真实的位置值?
这是我的代码在键盘中会出现的方法:
-(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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该数字是无符号 32 位整数的最大长度,并且跨平台和语言显示。您可能会看到维基百科文章。它是溢出的结果,是表示“未选择任何内容”的常量,或者有时是未初始化的内存。
The number is the maximum length of an unsigned 32 bit integer, and shows up across platforms and languages. You might see the Wikipedia article. It is the result of an overflow, a constant representing "nothing selected", or, sometimes uninitialized memory.
那将是
NSNotFound
,大概表明当前没有选择。That would be
NSNotFound
, presumably indicating that there's no current selection.