New to Telerik UI for Xamarin? Download free 30-day trial

Alert for Xamarin.iOS: Getting Started

This quick start tutorial demonstrates how to create a simple iOS application with TKAlert.

Setting up TKAlert

Now that our project is created and the TelerikUI.framework is added, we can start referencing and using the TelerikUI types:

Open your UIViewController file and add a reference to Telerik UI header file:

using TelerikUI;

Note that starting with Xcode 6 Apple doesn't generate the precompiled headers file automatically. That is why you should add import the UIKit framework before importing TelerikUI:

using UIKit;

In the ViewDidLoad method create a new instance of TKAlert and set its title and message properties:

TKAlert alert = new TKAlert ();
alert.Title = "Chicken or the egg";
alert.Message = "Which came first, the chicken or the egg?";

The next step is to add a few actions to TKAlert:

alert.AddActionWithTitle("Egg",  (TKAlert al, TKAlertAction action) => {
    TextLabel.Text = "It was the egg!";
    return true;
});

alert.AddActionWithTitle("Chicken",  (TKAlert al, TKAlertAction action) => {
    TextLabel.Text = "It was the chicken!";
    return true;
});

Now let's show TKAlert on the screen:

alert.Show (true);

And here is what it looks like:

Getting Started Alert example can be found in our Native Xamarin.iOS examples.

In this article