[英]UITableView on a UIView with UITapGestureRecognizer (cell selection doesn't work)
I have some problems with using a UITableView on a UIView which haves a UITapGestureRecognizer. 我在具有UITapGestureRecognizer的UIView上使用UITableView时遇到一些问题。 If I click on a UITableViewCell, the background does not change to the selected one (because no touch is received). 如果单击UITableViewCell,则背景不会更改为选定的背景(因为未收到任何触摸)。
I was in the assumption that if you add a childview to a parentview, the childview would be able to handle the touch and that everything would still work. 我假设如果将子视图添加到父视图中,则该子视图将能够处理触摸,并且一切仍将正常进行。 However, this is not the cas. 但是,这不是cas。 If I tap on a UITableviewCell, the tap is handled by this parentview and the cell is not selected. 如果我点击UITableviewCell,则此父视图处理该点击,并且未选中该单元格。
I already tried to subclass "UITapGestureRecognizer" to ignore touch events from UITableViewCell: (monotouch code) 我已经尝试对“ UITapGestureRecognizer”进行子类化,以忽略来自UITableViewCell的触摸事件:(单触摸代码)
public override bool ShouldReceiveTouch (UIGestureRecognizer recognizer, UITouch touch)
{
if (touch.View.GetType () == typeof(UITableViewCell))
return false;
return true;
}
It's not working because of I click on a cell, "touch.View.GetType ()" returns "UIView" and it's ignored. 因为单击单元格,所以它不起作用,“ touch.View.GetType()”返回“ UIView”,并且将其忽略。
Any idea's how I can make my tableview working on a UIView with a UITapGestureRecognizer? 有什么想法可以让我如何使用UITapGestureRecognizer使tableview在UIView上工作?
If I remove the "UITapGestureRecognizer" from the parentview, the tableview acts normal. 如果我从父视图中删除“ UITapGestureRecognizer”,则表视图的行为正常。
Thanks Matt 谢谢马特
When you create your UITapGestureRecogizer set the setCancelsTouchesInView property to NO. 创建UITapGestureRecogizer时,请将setCancelsTouchesInView属性设置为NO。 That should allow your UITableViewCell to receive the touch. 那应该允许您的UITableViewCell接收触摸。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.