Bug 19619 - Multiple event handlers on button press does not work on Mac, works on iOS
Summary: Multiple event handlers on button press does not work on Mac, works on iOS
Status: VERIFIED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.6.9
Hardware: PC Mac OS
: Normal normal
Target Milestone: 2.0.x
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2014-05-08 14:35 UTC by Chris Hamons
Modified: 2015-03-03 10:39 UTC (History)
7 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:
VERIFIED FIXED

Description Chris Hamons 2014-05-08 14:35:13 UTC
If you drop a button in a iOS and Mac application, and then hook up the following:
 
                        // Mac
			MyButton.Activated += (object sender, EventArgs e) => Console.WriteLine ("Hey");
			MyButton.Activated += (object sender, EventArgs e) => Console.WriteLine ("Ho");

                        // iOS
			MyAwesomeButton.TouchDown += (object sender, EventArgs e) => Console.WriteLine("Hey");
			MyAwesomeButton.TouchDown += (object sender, EventArgs e) => Console.WriteLine("Ho");

You will see "Hey" on Mac and "Hey" "Ho" on iOS. This seems wrong.
Comment 1 Ram Chandra 2014-07-15 10:58:04 UTC
I have checked this issue and I am also getting the same behavior for Xamarin.Mac but I am getting build error when I try to add two event handler with the same name for X.iOS.

Case 1: Xamarin.Mac

When I create a Mac application and call multiple event handlers on button press I observed that only first event handler is calling.

Screencast: http://www.screencast.com/t/i1FsCiHP

Case 2: Xamarin.iOS

I have added a button in Story board file and when I double click on the button it added the "TouchUpInside" event handler to the "viewcontroller" and now if I try to add another event handler with the same name I am getting build error ie. "implementation already defined".

Screencast: http://www.screencast.com/t/C4ruxfpC

Please let me know  if I am missing anything?

Environment Info:

=== Xamarin Studio ===

Version 5.1.3 (build 0)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
	Mono 3.6.0 ((no/5ff701f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000037

=== Xamarin.Android ===

Version: 4.12.5 (Enterprise Edition)
Android SDK: /Users/jatin66/Desktop/Backup/android-sdk-macosx
	Supported Android versions:
		1.6   (API level 4)
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: 7.2.5.5 (Enterprise Edition)
Hash: 87026b6
Branch: 
Build date: 2014-07-02 19:39:08-0400

=== Xamarin.Mac ===

Version: 1.8.0.8

=== Build Information ===

Release ID: 501030000
Git revision: 4676331632b3e5820ed4a92576594309907d778c
Build date: 2014-07-10 20:42:24-04
Xamarin addins: 571e972d874f74867110c205fc25b56048e7e93a

=== Operating System ===

Mac OS X 10.9.3
Darwin Jatin66s-iMac.local 13.2.0 Darwin Kernel Version 13.2.0
    Thu Apr 17 23:03:13 PDT 2014
    root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64
Comment 2 Chris Hamons 2014-07-15 11:01:26 UTC
Something like this:

			UIButton b = new UIButton ();
			b.TouchUpInside += (object sender, EventArgs e) => {
			};

			b.TouchUpInside += (object sender, EventArgs e) => 
			{

			};
Comment 3 Chris Hamons 2014-12-03 13:23:17 UTC
iOS:
			UIButton MyButton = new UIButton (UIButtonType.InfoDark);
			MyButton.Frame  = new RectangleF( 50, 50, 100, 100);
			MyButton.TouchUpInside += (object sender, EventArgs e) =>
			Console.WriteLine ("Hey");
			MyButton.TouchUpInside += (object sender, EventArgs e) =>
				Console.WriteLine ("Ho");
			Add (MyButton);

Mac:
		NSButton b = new NSButton (new RectangleF (0, 0, 100, 100));
			b.Activated += (object sender, EventArgs e) =>
				Console.WriteLine ("Hey");
			b.Activated += (object sender, EventArgs e) =>
				Console.WriteLine ("Ho");

			mainWindowController.Window.ContentView.AddSubview (b);
Comment 4 Chris Hamons 2014-12-03 17:05:17 UTC
I believe this and https://bugzilla.xamarin.com/show_bug.cgi?id=24058 are the same bug but will leave open until we research a fix to confirm.
Comment 5 Timothy Risi 2015-02-25 13:01:09 UTC
Fixed in master / 18454 - Can't add an event handler to a button after removing an event handler from that button.
Comment 6 Tim Uy 2015-02-27 21:27:14 UTC
Hi, I just noticed this problem in Xamarin.Mac. I was trying to attach to the Activated event in NSDatePicker and NSButton and am seeing the same issue where I cannot attach additional handlers.

---
=== Xamarin Studio ===

Version 5.7.2 (build 7)
Installation UUID: db3cdb23-e5f7-4e4e-913c-11179c7be9fa
Runtime:
	Mono 3.12.0 ((detached/b8f5055)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000077

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.Mac ===

Version: 1.12.0.8 (Business Edition)

=== Xamarin.iOS ===

Version: 8.6.2.26 (Business Edition)
Hash: 9905782
Branch: 
Build date: 2015-02-26 11:05:07-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/tim/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
Java SDK: /usr
No Java runtime present, requesting install.

=== Build Information ===

Release ID: 507020007
Git revision: dcf3f486177d3e625349b51a8f3be807e3fa7712
Build date: 2015-02-24 09:14:27-05
Xamarin addins: ea7c65bb7876e4a876ab365208e94acdf8f330ef

=== Operating System ===

Mac OS X 10.10.2
Darwin Tims-Air.netgear.com 14.1.0 Darwin Kernel Version 14.1.0
    Mon Dec 22 23:10:38 PST 2014
    root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64
Comment 7 Timothy Risi 2015-02-27 21:37:49 UTC
Hi Tim, the fix for adding multiple delegates to buttons will actually apply to all NSControls, not jsut buttons once we release a new build that has the fix in it.
Comment 8 Tim Uy 2015-02-28 15:39:35 UTC
Tim, do you have an ETA for this fix to get released?
Comment 9 Chris Hamons 2015-03-02 11:06:59 UTC
@Tim

I would expect this will go into Alpha within a week or two.
Comment 10 Abhishek 2015-03-03 10:39:59 UTC
I have checked this issue with the following builds:

Xamarin Studio Version 6.0 (build 9)
Installation UUID: 93e693b0-b53d-40f4-b29c-b61ff5cbe892
Runtime:
Mono 4.0.0 ((detached/2634099)
GTK+ 2.24.23 (Raleigh theme)
Package version: 400000017
Apple Developer Tools Xcode 6.1 (6604)
Build 6A1052d
Xamarin.Mac Version: 1.13.1.417 (Enterprise Edition)
=== Build Information ===
Release ID: 600000009
Git revision: d73d00b7002067b75f5181bf6b1553125fc51129
Build date: 2015-03-03 04:30:46-05
Xamarin addins: 36cdf9c68b1b93c6bf55be6a3f6d2bcb4ea1ebec
Operating System Mac OS X 10.10.0
Darwin 800BC.local 14.0.0 Darwin Kernel Version 14.0.0
Fri Sep 19 00:26:44 PDT 2014
root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64

This issue is working fine now. I observed that multiple event handlers on button press working properly on Mac. Here is the screencast for the same.
http://www.screencast.com/t/AJunTuuj0M8Z

This issue has been fixed, hence I am closing this issue.