Warning message for click button in iphone sdk 4.3

I am starting to program xcode. Please tell me how to display a warning message when we are about to press a button in xcode-iphone-4.3

My code is as follows:

- (IBAction)buttonPressed:(id)sender{ UIAlertView* mes=[[UIAlertView alloc] initWithTitle:@"Hello World!!!!!!" message:@"This is the Iphone app" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil]; [mes show]; [mes release]; 

Please help me with this.

+7
source share
3 answers
 -(IBAction)buttonOnePressed:(id)sender { UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Clicked button 1" message: @"Alert Message here" delegate: self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; [alert setTag:1]; [alert show]; } -(IBAction)buttonTwoPressed:(id)sender { UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Clicked button 2" message: @"Alert Message here" delegate: self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; [alert setTag:2]; [alert show]; } 

Below is the delegate method for tracking button clicks on Alertview.

  -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (alertView.tag == 1) { // UIAlertView with tag 1 detected if (buttonIndex == 0) { NSLog(@"user pressed Button Indexed 0"); // Any action can be performed here } else { NSLog(@"user pressed Button Indexed 1"); // Any action can be performed here } } else if (alertView.tag == 2) { // UIAlertView with tag 2 detected if (buttonIndex == 0) { NSLog(@"user pressed Button Indexed 0"); // Any action can be performed here } else { NSLog(@"user pressed Button Indexed 1"); // Any action can be performed here } } } 

You can set a tag on a UIAlertView if you have more than one UIAlertView , and you can determine which UIAlertView clicked in its clickedButtonAtIndex deletion method using the corresponding tag.

+22
source

In IBAction you need to write the code and give Connections to the button

+1
source

Create an IBAction for your button and add code to view alerts in this method.

0
source

All Articles