Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Displaying alerts


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.

Getting ready

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.

How to do it…

Perform the following steps to implement the UIAlertView in the app:

  1. 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...