user2931321 user2931321 -4 years ago 148
iOS Question

didSelectRowAt not getting called

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

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.

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download