Return to Snippet

Revision: 33200
at October 7, 2010 01:50 by BenClayton


Initial Code
// place this code in a UIViewController subclass

- (void)debugButtonPressed:(id)sender
{
 UIActionSheet* action = [[UIActionSheet alloc] 
        initWithTitle:@"Menu" 
        delegate:self 
        cancelButtonTitle:@"Continue"
        destructiveButtonTitle:@"Quit" 
        otherButtonTitles:@"Debug",nil ];
 [action showInView:self.view];
 [action release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
 switch (buttonIndex) {
  case 0: // Quit
   NSLog(@"Quit");
   break;
 case 1: // Continue
   NSLog(@"Continue");
   break;
  case 2: // Debug
   NSLog(@"Debug");
   break;
 }
}

Initial URL

                                

Initial Description
Here's a quick snippet for popping up a list of options using the UIActionSheet in iPhone OS.

What's slightly confusing is that the index of the 'cancelButton' is 1, and 'destructiveButton' is 0, even though 'cancelButton' is listed first in the initWithTitle selector. This gets me each time!

Initial Title
iPhone: Pop up a list of options

Initial Tags

                                

Initial Language
Objective C