'cancelsTouchesInView set to false interfering with UIButton touches

I have a gesture recogniser like so

let keyboardDismissTG: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard(_:)))
keyboardDismissTG.cancelsTouchesInView = false
self.view.addGestureRecognizer(keyboardDismissTG)

The cancelsTouchesInView was set to false so that I could intercept when a user taps on a UITableViewCell. Although this is conflicting when the user is tapping on a UIButton. Basically, when the user taps on UIButton, the touch is not getting delivered to the UIButton but instead just the keyboard is dismissed and user has to tap on UIButton again to continue. Any help would be appreciated.

Setting cancelsTouchesInView to false for a UITableView and true for a UIButton does work, but I'm hoping there's a better solution than this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source