UITableViewCell 选择 UITextView

发布于 2024-12-02 03:15:14 字数 348 浏览 1 评论 0原文

我陷入了单元格选择的困境。我有嵌入 UITextView 对象的自定义单元格。它不可编辑,不可滚动,启用用户交互。我无法在此视图上选择单元格。

我尝试过同样的事情,但是使用 UITextField 对象并且选择有效。

有什么想法如何让它发挥作用吗?

这是测试项目。只有一个表视图和一个单元格。此单元格中有一个文本视图和一个文本字段。您可以选择文本字段上方的单元格,但不能选择文本视图上方的单元格。

I get stuck with my cell selection. I have custom cell with UITextView object embedded in. It is not editable, not scrollable, with user interaction enabled. And I can not select cell over this view.

I've tried the same thing but with UITextField object and selection works.

Any ideas how to make it work?

This is the test project. There is just one table view with one cell. There is one text view and one text field in this cell. You can select the cell over the text field and can not over the text view.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

深海里的那抹蓝 2024-12-09 03:15:14

关闭文本视图上的“用户交互已启用”,选择将正常工作(MainStoryboard.storyboard->表视图控制器->表视图->表视图部分->自定义表视图单元格->文本视图)。允许用户在文本视图上进行交互是指在表格视图单元格获取点击之前捕获点击。由于您的文本视图不可滚动或可编辑,因此您不希望启用用户交互。

Turn off "User Interaction Enabled" on your text view and the selection will work fine (MainStoryboard.storyboard->Table View Controller->Table View->Table View Section->Custom Table View Cell->Text View). Allowing user interaction on the text view is capturing the taps before the table view cell gets them. Since your text view isn't scrollable or editable, you don't want user interaction enabled.

西瓜 2024-12-09 03:15:14

只是稍微阐述一下约翰·斯蒂芬的答案(据我所知这是最好的答案)

我已经通过子类化 UITextView 和重写 canBecomeFirstResponder 尝试过:

@interface MyTextView : UITextView

@end

@implementation MyTextView

- (BOOL)canBecomeFirstResponder {
  return NO;
}

@end

我还设置了 editableselectablescrollEnabledNO

MyTextView *textView = [MyTextView new];
textView.editable = NO;
textView.selectable = NO;
textView.scrollEnabled = NO;

这些都不起作用。 :(

Just to expound a bit on John Stephen's answer (which is the best as far as I can tell).

I've tried this by subclassing UITextView and overriding canBecomeFirstResponder:

@interface MyTextView : UITextView

@end

@implementation MyTextView

- (BOOL)canBecomeFirstResponder {
  return NO;
}

@end

I've also set editable, selectable, and scrollEnabled to NO:

MyTextView *textView = [MyTextView new];
textView.editable = NO;
textView.selectable = NO;
textView.scrollEnabled = NO;

None of these worked. :(

莳間冲淡了誓言ζ 2024-12-09 03:15:14

对于编程解决方案,相当于 John 对 Storyboards 的回答 是:

textView.isUserInteractionEnabled = false

The equivalent of John's answer for Storyboards for programmatic solution is:

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