TableViewCell is not clickable with one finger tap, but it is with two fingers

后端 未结 3 1674
小鲜肉
小鲜肉 2021-01-20 19:24

I created a table view and the tableViewCell is not clickable with one finger, but when I try to click the tableViewCell with two fingers the click event takes place. I don\

相关标签:
3条回答
  • 2021-01-20 19:50

    You have the following line in your set up code:

    self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(InvitePeopleVC.dismissKeyboard)))
    

    That sets up a gesture recognizer for your whole view and that would swallow any touches on the main view. If you remove that, you should get the table cell selection working correctly :)

    0 讨论(0)
  • 2021-01-20 19:52

    The Tap gesture you have added in the code is causing the issue. Tapgesture recogniser is listening to the user tap actions in the view. The cell select listner is being blocked by the added Tap gesture.

    As @Fahim said, if you remove the tap gesture from your code, then cell selection will work smoothly.

    0 讨论(0)
  • 2021-01-20 20:06

    A more elegant way of dealing with the tap issue is:

              let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(AppController.dismissKeyboard))
    
              view.addGestureRecognizer(tap)
    
              //this is the KEY of the fix
              tap.cancelsTouchesInView = false
    

    This way you can keep your gesture recognizer and still get the table view action in one single tap/selection.

    0 讨论(0)
提交回复
热议问题