0
votes

So I have a view in which it has some view which has a UITapGestureRecognizer on an image and I have a table view. The issue is that when I tap on a table view cell and the view which has a tap gesture recognizer on it is behind it, the action of that UITapGestureRecognizer is also executed. Question is how do I disable this so that when the table view didSelectRowAtIndexPath is executed the tap gesture recognizer action is not performed? By the way I have set :

 tapGestureRecognizer.cancelsTouchesInView = NO;

I've also tried doing:

- (IBAction) handleTapGesture:(UITapGestureRecognizer *) sender {

    if ([sender.view isKindOfClass:[TileViewController class]]){
        NSLog(@"CANCEL THIS");
    }

   if ([sender.view isKindOfClass:[UITableView class]]){
        NSLog(@"CANCEL THIS");
    }
}

but it never went into the if statements

3

3 Answers

2
votes

Make sure you're adding the tap gesture recognizer to the image, not the entire view or tableview.

[myImage addGestureRecognizer:tapGestureRecognizer];
2
votes

You can also manage this by implementing gestureRecognizer:shouldReceiveTouch: and using the view's class to determine what action to take. This approach has the advantage of not masking taps in the region directly surrounding the table (these areas' views still descend from the UITableView instances, but they do not represent cells).

Caveat: there is an assumption that Apple won't change the classname.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return ![NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"];
}
0
votes

Set

yourView.userInteractionEnabled = NO;

on the view you're putting in the table cell. That should cancel touches on all child views. You can probably easily set it in your cellForRowAtIndexPath function.