Tuesday, September 1, 2009

UIAlertView with more than one button

Taken from the UICatalog sample code.

Ensure the header file contains the following:

Code:
@interface YourViewController : UIViewController 
Add the following in the class where the alert is needed:

Code:
- (void)alertOKCancelAction {
// open a alert with an OK and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
Use this delegate method to process respond to the user input:

Code:
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1)
{
NSLog(@"User clicked OK");
} else {

NSLog(@"User clicked Cancel");
}
}


Reference: Stitch@iphonedevsdk.com

No comments:

Post a Comment

Followers