Walter Walter - 1 year ago 75
iOS Question

Double tap function is accumulating each time table is loaded

I have a double tap recognizer that loads a function when a table row is double tapped.

The table is loaded based on data from another table. When reloading the data, or selecting another row form the previous table (and loading different data), the double-tap with call the action once more for each time new data is loaded.

So the first time, I get the value 1 once. Then I reload data, and I get it twice, etc.

When this function is loaded with a single tap (in didSelectRowAtIndex) it behaves normally.

It seems like the double tap function accumulates each time the table is reloaded.

func doubleTap(recognizer: UITapGestureRecognizer) {



sample code 1

sample code 2

Answer Source

Here's the answer in case anyone is looking:

At first I tried putting "addGestureRecognizer" in ViewDidLoad, but then it turns out I actually needed to keep the gesture recognizer in the cellForRowAtIndexPath area- if I don't do that then it makes the entire table tappable, not just the rows. Having the gesture recognizer in cellForRowAtIndexPath caused its accumulation each time the table loaded.

Thus, I loaded didEndDisplayingCell and I put cell.removeGestureRecognizer(doubleTap) inside there. That way when the table is reloaded, the existing cells remove the double tap before adding it again to the new cells.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download