Bug 931 - UITapGestureRecognizer fails with "unrecognized selector sent"
Summary: UITapGestureRecognizer fails with "unrecognized selector sent"
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2011-09-20 11:03 UTC by René Ruppert
Modified: 2011-09-22 18:52 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description René Ruppert 2011-09-20 11:03:25 UTC
See simple example below. The recognizer has a class member reference. It does not help to make the delegate a class method. Tapping the window crashes the app.

I'd need a workaround very urgently :-(

using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;

namespace UISegmentDemo
{
	public class Application
	{
		static void Main (string[] args)
		{
			UIApplication.Main (args);
		}
	}
	
	// The name AppDelegate is referenced in the MainWindow.xib file.
	public partial class AppDelegate : UIApplicationDelegate
	{
		// This method is invoked when the application has loaded its UI and its ready to run
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			window.MakeKeyAndVisible ();
			
			this.oRec = new UITapGestureRecognizer ();
			this.oRec.AddTarget(delegate
			{
				Console.WriteLine("TAP");
			});
			this.oRec.NumberOfTapsRequired = 1;
			window.AddGestureRecognizer (this.oRec);
	
			return true;
		}
		
		private UITapGestureRecognizer oRec;
	}
}
Comment 1 René Ruppert 2011-09-20 11:08:22 UTC
Forgot to mention: this works in the simulator but crashes on the device!
Tested in MT 4.2 beta and iOS 4.3 and iOS 5 beta 7
Comment 2 René Ruppert 2011-09-20 11:11:15 UTC
And another note: it works if I use

this.oRec.AddTarget ( this, new MonoTouch.ObjCRuntime.Selector ( "ViewTapped:" ) );

and 

[Export( "ViewTapped:" )]
public void ViewTapped ( UIGestureRecognizer sender )
{
	Console.WriteLine("TAP!");
}

instead of adding an NSAction delegate. So at least I have a workaround.
Comment 3 Sebastien Pouliot 2011-09-22 17:55:11 UTC
Confirmed, code in original description works on simulator but crash on devices.
Comment 4 Sebastien Pouliot 2011-09-22 18:03:34 UTC
It's a linker issue, using "Don't link" on the device build makes it work.
Comment 5 Sebastien Pouliot 2011-09-22 18:52:37 UTC
A [Preserve (Conditional = true)] attribute was missing on the method that called the NSAction (and was [Export]ing the internal selector used). Fixed in master and monotouch-4.2