Declare the UIAlertView delegate in the yourViewController.h:
1 |
<UIAlertViewDelegate> |
Create the alertView:
1 2 3 4 5 6 7 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Here is my alert title." message: @"Here is my alert message." delegate: self cancelButtonTitle: @"Cancel" otherButtonTitles: @"OK", nil]; [alert show]; |
Detect which alertView button was tapped:
1 2 3 4 5 6 7 8 |
if (buttonIndex==0) { // button 0 tapped NSLog(@"Cancel %d", buttonIndex); }else if (buttonIndex==1){ // button 1 tapped NSLog(@"OK %d", buttonIndex); } |