奇怪的问题:UITableViewCell 不会检测到触摸,尽管它的附件视图可以 [英] Weird issue: UITableViewCell would not detect touch although it's accessory view does
问题描述
我有一个非常简单的 UITableView
,里面有一个 UITableViewCell
.DataSource
和 Delegates
已正确设置.它正确显示数据.但是 tableview 的单元格没有响应触摸.尽管单元格的附件视图确实响应触摸.
I have a very simple UITableView
with a UITableViewCell
in it. DataSource
and Delegates
are correctly set up. It shows data correctly. But the tableview's cell is not responding to touch. Although cell's accessory view does respond to touch.
我尝试为单元格和单元格的附件视图创建转场.只有连接到附件视图的 segue 工作.(同样 didSelectRowAtIndex
路径方法不会被调用)
I tried creating segues for both cell and cell's accesory view. Only the segue connected to accessory view works. (Also didSelectRowAtIndex
path method wouldn't get called)
可能是什么原因,以及如何调试这样的问题?
What could be the reason, and how to debug an issue like this?
推荐答案
终于找到了问题所在.UITableViewCell 没有检测到触摸的原因是,我在视图中添加了一个点击手势识别器,即使我点击单元格,这个点击手势甚至会触发并取消任何其他事件.为了避免需要添加以下行.
Finally I found the problem. The reason why UITableViewCell was not detecting touches was, I had a tap gesture recognizer added to the view and, even when I tap on the cell, this tap gesture even would fire and cancel out any other events. To avoid that following line needed to be added.
迅捷
tap.cancelsTouchesInView = false
目标 C
[tap setCancelsTouchesInView:NO];
这篇关于奇怪的问题:UITableViewCell 不会检测到触摸,尽管它的附件视图可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!