11

I've set a Tap Gesture Recognizer in my ViewController via the Storyboard (so all the tap in the view, will hide the keyboard if this one is showed)

The thing is that now, I have add a TableView in this View, and when I clic on a cell, the methode set with the Tap Gesture Recognizer is call, not didSelectRowAtIndexPath.

The "funny" thing, is that if I stay on the cell for 2seconds or more, the delegate didSelectRowAtIndexPath is called, not the TapGestureRecognizer methode.

Could you guys explain what happen here ? where and why am I wrong ?

  • when keyboard will open then add tap gesture and when keyboard will hide then remove tap gesture from the view, this is one way to do – Jaimish Jan 22 '16 at 10:46
  • @Jaimish : I've done that, it work perfectly for the TapGestureRecognizer method, but now, on my TableView, nothing is called when I single tap on a cell, and didSelectRowAtIndexPath is called when I stay press on the cell for 2secondes or more, I still wonder why. – Vincent 'On-arap' Burel Jan 22 '16 at 11:03
  • You have tried the @Jan Greve answer? – Jaimish Jan 22 '16 at 11:15
  • Provide some code of Textfield or Textview delegate and also didselect method of tableview – Jaimish Jan 22 '16 at 11:17

2 Answers2

23

Your UITapGestureRecognizer probably cancels the touch event when successfully recognizing a touch.

Try setting

tapGestureRecognizer.cancelsTouchesInView = NO;

For a more thorough read on this topic, have a look an the conceptual docs on gesture recognition.

Tobi Nary
  • 4,566
  • 4
  • 30
  • 50
  • after Updating my code tahnks to Jaimish, I'm sure I have no gestures set on my view anymore, but the didSelectRowAtIndexPath is still called only when I stay press on the cell for more than 2secondes, nothing is call when I single tap on it (however, the cell still "blink" as it should when single tapped, is it possible that the code call another delegate, other tahn didSelectRowAtIndexPath ?) – Vincent 'On-arap' Burel Jan 22 '16 at 11:09
  • Is your gesture recognizer's action called? How are you 'sure'? Have you imlemented `tableView(_ tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath?` on your delegate? That could prohibit it as well. – Tobi Nary Jan 22 '16 at 11:14
  • Yep, I found out that in the storyboard, some gestureRecognizer were set to non-existants methods, after deleted them, it work perfectly !! Thanks by the way :) – Vincent 'On-arap' Burel Jan 22 '16 at 11:19
  • I recon that makes my answer correct and helpful then. Feel free to accept it. – Tobi Nary Jan 22 '16 at 11:51
  • @SmokeDispenser It is still not working for me , i am not table to select the items from my table view, i have implemented the `func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)` method – Samarth Kejriwal Aug 27 '17 at 06:09
  • @SamarthKejriwal this is not a forum. If you have a question yourself, feel free to ask it complying to [ask] after searching for it here. Explain in your question what you have tried and what didn't work. – Tobi Nary Aug 27 '17 at 07:26
  • Thank you very much man! Now i can use both didselectrowatindexpath and tapgesture with a single tap ! – Emin Turk Jul 06 '19 at 09:34
-3

Better way is don't use didSelectRowAtIndexpath method.

if you have to implement gestures on table view cell then create tap gesture in cellForRowAtIndexpath and using tag identify particular cell click.

Manish Mahajan
  • 2,062
  • 1
  • 13
  • 19