Alert View in iPhone

Introduction

In this article I will create a Single View application. Here I will implement an alert view. For this here we write code in the ViewController.m Objective-C class.

To understand it we use the following.

Step 1

Open XCode by double-clicking on it.

Step 2

Create a New XCode Project by clicking on it.

Step 3

Now Select Single View Application and click on Next.

Step 4

Now provide your Product Name and Company Identifier.

Step 5

Select the location where you want to save your project and click on Create.

Step 6

Now here we write the code.

ViewController.h

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end

ViewController.m

#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Hello" message:@"This is an alert view" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"Option1",@"Option2",nil];
[alert show];
[alert release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end

Step 7

Finally we click on the run button to show the output.

Step 8

Output  in iPhone:

Output-in-iPhone.png