Posted By

BenClayton on 10/07/10


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

bobbym245
Tintenklecks
cnathan


iPhone: Pop up a list of options


 / Published in: Objective C
 

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!

  1. // place this code in a UIViewController subclass
  2.  
  3. - (void)debugButtonPressed:(id)sender
  4. {
  5. UIActionSheet* action = [[UIActionSheet alloc]
  6. initWithTitle:@"Menu"
  7. delegate:self
  8. cancelButtonTitle:@"Continue"
  9. destructiveButtonTitle:@"Quit"
  10. otherButtonTitles:@"Debug",nil ];
  11. [action showInView:self.view];
  12. [action release];
  13. }
  14.  
  15. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  16. switch (buttonIndex) {
  17. case 0: // Quit
  18. NSLog(@"Quit");
  19. break;
  20. case 1: // Continue
  21. NSLog(@"Continue");
  22. break;
  23. case 2: // Debug
  24. NSLog(@"Debug");
  25. break;
  26. }
  27. }

Report this snippet  

You need to login to post a comment.