
To implement an Objective-C protocol in C#, simply declare a sub-class
of the protocol. In the case of the UIAlertView class, the subclass would
look like this:
public class
MyAlertDelegate : UIAlertViewDelegate {
public override void
Clicked (UIAlertView alertview,
int buttonIndex)
{
Console.WriteLine(buttonIndex.ToString()
+
"
clicked.");
}
}
To implement the protocol, create an instance of the MyAlertDelegate class:
MyAlertDelegate
alertDelegate;
alertDelegate = new
MyAlertDelegate();
And then use it together with the UIAlertView object, like this:
UIAlertView alert =
new
UIAlertView("Hello, World!",
"Welcome to Xamarin, ",
alertDelegate,
"OK",
"Cancel");
alert.Show();
When a button in the alert view is now tapped, a message will be
printed in the console window.
Attending the Xamarin Training in Singapore. Check out this link for more details.
No comments:
Post a Comment