0

I am using tap gesture and tableview on the same controller. Found that when gesture using on uiviewcontroller and tableview, the tableview didSelectRowAtIndexPath will not working. But i want both things on view controller. Any one face this stuff please advice me what to do.

kiran
  • 4,285
  • 7
  • 53
  • 98
  • possible duplicate of [UITapGestureRecognizer breaks UITableView didSelectRowAtIndexPath](http://stackoverflow.com/questions/8192480/uitapgesturerecognizer-breaks-uitableview-didselectrowatindexpath) – Chan May 07 '15 at 06:14

1 Answers1

1

You need to implement UIGestureRecognizerDelegate method gestureRecognizer: shouldReceiveTouch: which returns a BOOL value. If YES is returned the Tap on the touched view will be handled else the tap will be discarded and touch functionality of the underlying view will work.

In your case you need to omit tap events of Tap gesture on table view, you can do so as-

#pragma mark UIGestureRecognizerDelegate methods

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if ([touch.view isDescendantOfView:tableViewInstance]) {

        // return NO 
        // to skip gesture recognizer events
        return NO;
    }
    // return YES
    // to handle gesture recognizer events on other views
    return YES;
}
Sanjay Mohnani
  • 5,947
  • 30
  • 46