1
votes

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

1
you want to change selected cell Background change while u tap on it..? - Nitin Gohel
Yes, but I know how to change the Background for a selected cell. The problem is that when I add my Table on a View with a UITapGestureRecognizer, the Cell will not get "selected" because the tap is handled by the parentview - Matt

1 Answers

5
votes

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