didSelectRowAtIndexPath is in conflict with Tap Gesture Recognizer
Asked Answered
T

2

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 ?

Torch answered 22/1, 2016 at 10:40 Comment(4)
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 doPeripatetic
@Peripatetic : 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.Archimandrite
You have tried the @Jan Greve answer?Peripatetic
Provide some code of Textfield or Textview delegate and also didselect method of tableviewPeripatetic
C
24

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.

Crore answered 22/1, 2016 at 10:46 Comment(7)
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 ?)Archimandrite
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.Crore
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 :)Archimandrite
I recon that makes my answer correct and helpful then. Feel free to accept it.Crore
@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) methodClive
@SamarthKejriwal this is not a forum. If you have a question yourself, feel free to ask it complying to How to Ask after searching for it here. Explain in your question what you have tried and what didn't work.Crore
Thank you very much man! Now i can use both didselectrowatindexpath and tapgesture with a single tap !Kv
I
-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.

Indomitable answered 29/3, 2018 at 7:51 Comment(1)
@EdwardAnthony Can you please explain what is wrong here so I can learn things.Indomitable

© 2022 - 2024 — McMap. All rights reserved.