UITapGestureRecognizer conflicts with didSelectRowAtIndexPath

long before I ask about it, I will try other solutions, and it does not work.

this is my code

override func viewDidLoad() {
    super.viewDidLoad()

    let tapGesture = UITapGestureRecognizer(target: self, action: "didTouchBoard:")
    view.addGestureRecognizer(tapGesture)
    tapGesture.cancelsTouchesInView = true
}

when I click anywhere, it will hide the keyboard if it exists, but if I click on tableviewcell or collectionviewcell, it will not click

I will try this tapGesture.cancelsTouchesInView but not working

+4
source share
2 answers

If you want the table view to be touched, change tapGesture.cancelsTouchesInView

tapGesture.cancelsTouchesInView = false
+4
source

You must add UITextFeildDelegate methods to enable and disable the selection gesture in the view.

  • tapGesture

let tapGesture = UITapGestureRecognizer(target: self, action: "didTouchBoard:")

  1.  func textFieldDidBeginEditing(textField: UITextField) {
    self.view.addGestureRecognizer(self.tapGesture) }
    

    func textFieldDidEndEditing (textField: UITextField) {       self.view.removeGestureRecognizer(self.tapGesture)   }

,

+3

All Articles