UITableViewCell 选择 UITextView
我陷入了单元格选择的困境。我有嵌入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
关闭文本视图上的“用户交互已启用”,选择将正常工作(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.
只是稍微阐述一下约翰·斯蒂芬的答案(据我所知这是最好的答案)。
我已经通过子类化
UITextView
和重写canBecomeFirstResponder
尝试过:我还设置了
editable
、selectable
和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 overridingcanBecomeFirstResponder
:I've also set
editable
,selectable
, andscrollEnabled
toNO
:None of these worked. :(
对于编程解决方案,相当于 John 对 Storyboards 的回答 是:
The equivalent of John's answer for Storyboards for programmatic solution is: