-(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.
Suraj mirajkar
source share