Search code examples
swiftuigesturerecognizeruitapgesturerecognizer

Add TapGesture to view under tableView


Hello I have a view and inside of this view I have a tableView. What I would like to do is add a tap gesture on the view. My issue is that when I do this, the gesture shadows the tableView default tap gesture and becomes useless. Is there any way to add a gesture to the view underneath without affecting my tableView? Thank you in advance:

Code:

self.mainView.addGestureRecognizer(UITapGestureRecognizer.init(target: self, action: #selector(mainViewTap(_:))))

Solution

  • Use a button under tableView but above your view. There might be other ways, bit this seems like a quick fix.