我在 UITableViewCell
中放置了一个小的 UIView
。
- 如果点击 这样的
UIView
,我想打开一个弹出窗口。 - 如果点击外部,例如
UIView
,我想执行它在UITableView
“didSelectRowAtIndexPath”功能。
目前正在发生的事情是,当我点击 View 时,两件事都会发生:弹出窗口打开并触发“didSelectRowAtIndexPath”函数。 p>
我如何确保在单击 UIView
时不会触发“didSelectRowAtIndexPath”函数?
当前实现:
我在自定义 UITableViewCell
类中为 UIView
定义了一个 UITapGestureRecognizer
。
让 tapGesture = UITapGestureRecognizer(目标: self , Action :#selector(MyCustomTableViewCell.clickOnHelp(_:)))
myClickAreaUIView.addGestureRecognizer(tapGesture)
最佳答案
我建议的最佳解决方案是将 UIView
更改为 UIButton
并使用按钮上的 touchUpInside
处理触摸。
这样你就可以达到你的目标,因为 UIButton
自动阻止触摸事件转发到 superview
关于iOS:单击 TableCellView 内的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39123233/