Alert message for the button click in iphone sdk 4.3
-(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 to track which button on Alertview is hit.
-(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 tag to UIAlertView
in case you have more than one UIAlertView
s and can determine which UIAlertView
button is clicked in its delegate method clickedButtonAtIndex
using its respective tag.