Google

UIAlertView in Xcode 4.2

Written on:April 8, 2012
Comments
Add One

In this video tutorial I am going to explain about UIAlertView using Xcode 4.2.

  • What is UIAlertView
  • How to use UIAlertView
  • Sample Code for UIAlertView in Xcode 4.2
  • How to use IF conditions with UIAlertView

Here is the video tutorial

UIAlertView displays an alert to the user like message box with options like Yes/Cancel or anything you can think of based on what you are trying to achieve.

UIAlertView Sample code

-(void) viewDidLoad{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome"
					            message:@"This is UIAlertView"
						    delegate:self
                                           cancelButtonTitle:@"Okay"   
                                           otherButtonTitles:@"button 1", @"button 2",nil];    
   
			[alert show];
}

How to use IF conditions with UIAlertView with button index check

 

-(void)alertView:(UIAlertView *)actionsheet clickedButtonAtIndex:(NSInteger)buttonIndex{
					    if(buttonIndex == 0){
					        UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Button Index”    
                                                message:@" You clicked button index 0”  
                                                delegate:self
	                                        cancelButtonTitle:@"Okay"
						otherButtonTitles:nil];           
	      [alert1 show]; 
    }
}

Apple Developer Manual -  UIAlertView

Feel free to comment with any improvements for the article. 

Thanks,
Abhi