简体   繁体   中英

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. If I click on a UITableViewCell, the background does not change to the selected one (because no touch is received).

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. If I tap on a UITableviewCell, the tap is handled by this parentview and the cell is not selected.

I already tried to subclass "UITapGestureRecognizer" to ignore touch events from UITableViewCell: (monotouch code)

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.

Any idea's how I can make my tableview working on a UIView with a UITapGestureRecognizer?

If I remove the "UITapGestureRecognizer" from the parentview, the tableview acts normal.

Thanks Matt

When you create your UITapGestureRecogizer set the setCancelsTouchesInView property to NO. That should allow your UITableViewCell to receive the touch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM