title: Using AddTarget for UIButton with MonoTouch and C#
body: <p><strong>EDIT: I now get the exception:</strong></p>
  
  <pre><code> Stacktrace:
  
    at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) &lt;IL 0x0009f, 0xffffffff&gt;
    at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
    at MonoTouch.UIKit.UIApplication.Main (string[]) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:43
    at MapKit01.Application.Main (string[]) [0x00000] in /Users/andre/Downloads/MapKit03/MapKit03/Main.cs:20
    at (wrapper runtime-invoke) &lt;Module&gt;.runtime_invoke_void_object (object,intptr,intptr,intptr) &lt;IL 0x00050, 0xffffffff&gt;
  
  Native stacktrace:
  
  0   MapKit01                            0x00091eac mono_handle_native_sigsegv + 284
  1   MapKit01                            0x00005788 mono_sigsegv_signal_handler + 248
  2   libsystem_c.dylib                   0x9533f8cb _sigtramp + 43
  3   ???                                 0xffffffff 0x0 + 4294967295
  4   UIKit                               0x0274f258 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
  5   UIKit                               0x02810021 -[UIControl sendAction:to:forEvent:] + 66
  6   UIKit                               0x0281057f -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 578
  7   UIKit                               0x0280f6e8 -[UIControl touchesEnded:withEvent:] + 546
  8   UIKit                               0x0277ecef -[UIWindow _sendTouchesForEvent:] + 846
  9   UIKit                               0x0277ef02 -[UIWindow sendEvent:] + 273
  10  UIKit                               0x0275cd4a -[UIApplication sendEvent:] + 436
  11  UIKit                               0x0274e698 _UIApplicationHandleEvent + 9874
  12  GraphicsServices                    0x04d40df9 _PurpleEventCallback + 339
  13  GraphicsServices                    0x04d40ad0 PurpleEventCallback + 46
  14  CoreFoundation                      0x012bfbf5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
  15  CoreFoundation                      0x012bf962 __CFRunLoopDoSource1 + 146
  16  CoreFoundation                      0x012f0bb6 __CFRunLoopRun + 2118
  17  CoreFoundation                      0x012eff44 CFRunLoopRunSpecific + 276
  18  CoreFoundation                      0x012efe1b CFRunLoopRunInMode + 123
  19  GraphicsServices                    0x04d3f7e3 GSEventRunModal + 88
  20  GraphicsServices                    0x04d3f668 GSEventRun + 104
  21  UIKit                               0x0274bffc UIApplicationMain + 1211
  22  ???                                 0x0e0c66ad 0x0 + 235693741
  23  ???                                 0x0e0c61b0 0x0 + 235692464
  24  ???                                 0x0e0c5f0c 0x0 + 235691788
  25  ???                                 0x0e0c5ccc 0x0 + 235691212
  26  ???                                 0x0e0c5eb6 0x0 + 235691702
  27  MapKit01                            0x00009b52 mono_jit_runtime_invoke + 722
  28  MapKit01                            0x0016d02e mono_runtime_invoke + 126
  29  MapKit01                            0x00171224 mono_runtime_exec_main + 420
  30  MapKit01                            0x00176615 mono_runtime_run_main + 725
  31  MapKit01                            0x000671e5 mono_jit_exec + 149
  32  MapKit01                            0x00204fd4 main + 1988
  33  MapKit01                            0x00002b75 start + 53
  34  ???                                 0x00000004 0x0 + 4
  
  =================================================================
  Got a SIGSEGV while executing native code. This usually indicates
  a fatal error in the mono runtime or one of the native libraries 
  used by your application.
  =================================================================
  </code></pre>
  
  <p><strong>Question</strong>:
  I like to use some code I found in Objective-C in my C# project.
  It works fine at all but to use the line with addTarget let me think since a couple of hours with no working result.
  So this is the original source for:</p>
  
  <pre><code>  UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  </code></pre>
  
  <p>And this is what I try with:</p>
  
  <pre><code>  UIButton infoButton = new UIButton(UIButtonType.DetailDisclosure);
    infoButton.AddTarget(infoButton, new MonoTouch.ObjCRuntime.Selector("showDetails"),UIControlEvent.TouchUpInside);
  
    public void showDetails(object sender, EventArgs e)
  </code></pre>
  
  <p>The result is not very nice the app crash without any response when I click the button ...</p>
  
  <p>Can you help me please how to use it in C# the right way?</p>
  
  <p>Thanks</p>
  
  <p>Andre</p>