1

I have added UITableView on top of UIView. Added tap gesture to UIView using below code:

   let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapToClose))
    tapGesture.cancelsTouchesInView = false
    tapGesture.numberOfTapsRequired = 1
    vwForTouchClose.addGestureRecognizer(tapGesture)

when I select on cell didSelectRowAt not getting called instead gesture method is called. Below is ur code at didSelectRowAt:

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    tableView.deselectRow(at: indexPath, animated: true)

}

Please help me to solve this issue.

user2931321
  • 468
  • 1
  • 7
  • 28

1 Answers1

2

You have to cancel UIGestureRecognizer's touches on the TableView. Use delegate method of Gesture Recognizer:

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

        return NO;
    }

    return YES;
}
NotABot
  • 516
  • 1
  • 8
  • 27