Alert: Getting Started

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

Prerequisites

This article assumes that you have followed the Downloading UI for iOS, Installing UI for iOS and Setting Up the project steps from the common Getting Started article.

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 ViewController.m file and add a reference to Telerik UI header file:

#import <TelerikUI/TelerikUI.h>

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:

#import <UIKit/UIKit.h>

If you are writing Swift, add the same line in your bridging header.

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

TKAlert *alert = [TKAlert new];
alert.title = @"Chicken or the egg";
alert.message = @"Which came first, the chicken or the egg?";
let alert = TKAlert()
alert.title = "Chicken or the egg?"
alert.message = "Which came first, the chicken or the egg?"
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" handler:^BOOL (TKAlert *alert, TKAlertAction* action) {
    _textLabel.text = @"It was the egg!";
    return YES;
}];

[alert addActionWithTitle:@"Chicken" handler:^BOOL (TKAlert *alert, TKAlertAction* action) {
    _textLabel.text = @"It was the chicken!";
    return YES;
}];
alert.addAction(withTitle: "Egg") { (TKAlert, TKAlertAction) -> Bool in
    self.textLabel.text = "It was the egg"
    return true
}

alert.addAction(withTitle: "Chicken") { (TKAlert, TKAlertAction) -> Bool in
    self.textLabel.text = "It was the chiken"
    return true
}
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:YES];
alert.show(true)
alert.Show (true);

And here is what it looks like: