简体   繁体   English

带有UITapGestureRecognizer的UIView上的UITableView(单元格选择不起作用)

[英]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.

相关问题 Scroll View中用于UIView的UITapGestureRecognizer不起作用 - UITapGestureRecognizer for UIView in Scroll View doesn't work 自定义 UIView 中的 UITapGestureRecognizer 不起作用 - UITapGestureRecognizer in custom UIView doesn't work 使用UITapGestureRecognizer在UIView之上的UIButton不起作用 - UIButton on top of UIView with UITapGestureRecognizer doesn't work Obj-C-在对UIView进行动画处理后,UITapGestureRecognizer无法正常工作吗? - Obj-C - UITapGestureRecognizer doesn't work after UIView is animated? 自定义表格视图单元格上的 UITapGestureRecognizer 不起作用 - UITapGestureRecognizer on custom table view cell doesn't work 在UIView和UITableView中冲突的UITapGestureRecognizer - Conflicting UITapGestureRecognizer in UIView and for UITableView UITapGestureRecognizer不适用于自定义UIView类 - UITapGestureRecognizer won't work for custom UIView class UITableView中的自定义单元的UITapGestureRecognizer - UITapGestureRecognizer for a custom cell in UITableView UITableView的单元格不能用作设置 - UITableView's cell doesn't work as setting tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath)将UITapGestureRecognizer添加到自定义UITableViewCell时不起作用 - tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) Doesn't work when I add a UITapGestureRecognizer to my custom UITableViewCell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM