4

I've added an action as anonymous method to my gesture recognizer

UITapGestureRecognizer tapGesture = new UITapGestureRecognizer ();
tapGesture.AddTarget (() => HandleTap (tapGesture));

How can I remove the target? UIGestureRecognizer.Token is needed.

testing
  • 19,681
  • 50
  • 236
  • 417

1 Answers1

2

RTFM is true here:

An instance of this class is returned when you invoke the UIGestureRecognizer's UIGestureRecognizer.AddTarget method. The AddTarget returns this token as a mechanism for later unsubscribing this particular action from the recognizer using the UIGestureRecognizer.RemoveTarget method.

UIGestureRecognizer.Token token = tapGesture.AddTarget (() => HandleTap (tapGesture));

if (token != null) {
    tapGesture.RemoveTarget (token);
}
testing
  • 19,681
  • 50
  • 236
  • 417