The UIAlertView
class provides us with the ability to display alert messages to the user. In this recipe, we will discuss how to use this class and respond to user input.
For this recipe, create an iPhone Single View Application project in Xamarin Studio and name it AlertViewApp
. Open the AlertViewAppViewController.xib
file in Xcode and add a button on its view. Don't forget to connect it to an outlet.
Perform the following steps to implement the UIAlertView
in the app:
In Xamarin Studio, open the
AlertViewAppViewController.cs
file and add the following method:private void ShowAlert(string title, string message) { // Create the alert UIAlertView alertView = new UIAlertView(); alertView.Title = title; alertView.Message = message; // Add buttons alertView.AddButton("OK"); alertView.AddButton("Cancel"); // Add event handler alertView.Dismissed += (sender, e) => { if (e.ButtonIndex == 0) { this.btnShowAlert.SetTitle...