UITextview 中的 textview.selectedRange.location 显示 2147483647

发布于 2024-10-10 06:07:30 字数 896 浏览 0 评论 0原文

我有一个文本视图,我想从该文本视图获取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉黛浅 2024-10-17 06:07:30

该数字是无符号 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.

暖阳 2024-10-17 06:07:30

那将是 NSNotFound,大概表明当前没有选择。

That would be NSNotFound, presumably indicating that there's no current selection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文