"Disconnect" UIKit UITapGestureRecognizer

I’m using @Jason King 's UITapGestureRecognizer from UIKit. I’m attaching it to an iOSTable using:

declare sub setUserInteractionEnabled lib UIKitLib selector "setUserInteractionEnabled:" (obj_id as ptr, yesNo as Boolean)
setUserInteractionEnabled(Table.Handle, true)
Table.AddGestureRecognizer(TapGestureRecognizer)		

I do this so that I can detect taps on various areas of my (custom) table cell and handle those taps in different ways. It all works well except when I put the iOSTable into editing mode. Then the UITapGestureRecognizer intercepts taps on the edit buttons (e.g. Delete button), which are part of the iOSTableDataSource interface, instead of firing the standard iOSTable events.

So I think the best thing for me to do would be to “disconnect” the UITapGestureRecognizer when I put the iOSTable into edit mode. However I can’t work out how to do that. Has anybody got any ideas?

Did you try RemoveGestureRecognizer ?

I did. It crashed my app in the iOS Simulator. Maybe I’m not using it properly?

I’ve never used UIGestureRecognizer (yet).

Did you create the AddGestureRecognizer for Table ?
UIKit seems to only have that function extending a View

My call to AddGestureRecognizer is in the original post, above. To remove it, I’ve tried this:

self.RemoveGestureRecognizer TapGestureRecognizer

but it crashes my app.

Yes but I see in your code you add the Gesture recognised to “Table”.

Unless Table is the name of your iOSView, you should remove the recognizer from Table and not from the the view.

I thought so too, but the RemoveGestureRecognizer method in iOSKit extends iOSView, not iOSTable. So I assumed that must be how it works. I’m not sure how I can use it with iOSTable?

It should work the same for an iOSTable as for an iOSView. Try:

declare sub removeGestureRecognizer lib UIKitLib selector "removeGestureRecognizer:" (viewHandle as ptr, recognizer as ptr) removeGestureRecognizer(table.Handle, recognizer)

That did the trick! Thanks Jason. :slight_smile: