UITextView does not respond to beginningOfDocument



我试图按照这篇文章在我的UITextView中获取某个单词的像素位置,但是以下代码:

UITextPosition *beginning = cell.textView.beginningOfDocument;

导致我的应用程序崩溃(似乎仅在iOS4中,但根据文档UITextInput beginningOfDocument自iOS3.2以来应该可用)。我尝试调试问题并获得以下输出:

(gdb) po cell
<ReadTableViewCell: 0x1bf25d60; baseClass = UITableViewCell; frame = (0 0; 320 44); userInteractionEnabled = NO; tag = 1248776; layer = <CALayer: 0x1bf25d20>>
(gdb) po [cell textView]
<UITextView: 0x1bf26810; frame = (5 4; 309 121); text = 'Subject Header
Detailed Content...'; clipsToBounds = YES; layer = <CALayer: 0x1bf26650>; contentOffset: {0, 0}>
(gdb) po [[cell textView] beginningOfDocument]
Target does not respond to this message selector.
(gdb)

有人可以给我一些关于如何解决或避免此问题的提示吗?提前感谢!!

UITextInput 从 iOS3.2 开始肯定可用,但遗憾的是 UITextView 从 iOS5.0 开始符合 UITextInput。它曾经使用 UITextInputTraits 协议。

在此线程中,有关如何调整以在 iOS4 上工作的更多信息:

UI 中的问题 iOS 4.3 中的 UITextView 开头文档

最新更新