EDIT: I see that you are extending UIViewController (which may not be advisable because it applies to all instances and subclasses of UIViewController), but you should still be able to set up the delegate. Make the following changes (code is pulled from this answer).
Extend UIGestureRecognizerDelegate
by writing extension UIViewController: UIGestureRecognizerDelegate {
Set the delegate when you add the gesture recognizer:
tap.delegate = self
Implement the following delegate method. It will need to be modified slightly to handle two tableviews.
// UIGestureRecognizerDelegate method
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
if touch.view?.isDescendantOfView(self.tableView) == true {
return false
}
return true
}
Previous answer:
If the cancelsTouchesInView
property of UIGestureRecognizer
is false the view underneath it will receive touches in addition to the gesture recognizer.
If you do want to effectively disable the gesture for that case, implement the delegate method gestureRecognizer(_:shouldReceive:)
and return false if the touch is in the tableview.
See https://developer.apple.com/documentation/uikit/uigesturerecognizer and https://developer.apple.com/documentation/uikit/uigesturerecognizerdelegate/1624214-gesturerecognizer.