If you want to intercept events from UIControl, you have a range of options: from using the C# lambdas and delegate functions to using the low-level Objective-C APIs.
The following shows how you would capture the TouchDown event on a button, depending on how much control you need:
Using the delegate syntax:
UIButton button = MakeTheButton (); button.TouchDown += delegate { Console.WriteLine ("Touched"); };
If you like lambdas instead:
button.TouchTown += () => { Console.WriteLine ("Touched"); };
If you want to have multiple buttons use the same handler to share the same code:
void handler (object sender, EventArgs args) { if (sender == button1) Console.WriteLine ("button1"); else Console.WriteLine ("some other button"); } button1.TouchDown += handler; button2.TouchDown += handler;
The C# events for UIControlEvent flags have a one to one mapping to individual flags. Sometimes you might want to have the same piece of code handle two or more events, in that case, use the UIControl.AddTarget method:
button.AddTarget (handler, UIControlEvent.TouchDown | UIControl.TouchCancel);
Using the lambda syntax:
button.AddTarget (()=> Console.WriteLine ("An event happened"), UIControlEvent.TouchDown | UIControl.TouchCancel);
If you need to use low-level features of Objective-C, like hooking up to a particular object instance and invoke a particular selector:
[Export ("MySelector")] void MyObjectiveCHandler () { Console.WriteLine ("Hello!"); } // In some other place: button.AddTarget (this, new Selector ("MySelector"), UIControlEvent.TouchDown);
Please note, if you implement the instance method in an inherited base class, it must be a public method.