Posted By

BenClayton on 10/27/10


Tagged


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

FumarMata
magickaito

cnathan


iPhone: Use UIAlertView to confirm a deletion


 / Published in: Objective C
 

You must add UIAlertViewDelegate to the protocols for your class

  1. // confirm the deletion..
  2. UIAlertView *alert = [[UIAlertView alloc]
  3. initWithTitle: theTitle
  4. message: msg
  5. delegate: self
  6. cancelButtonTitle: @"Cancel"
  7. otherButtonTitles: @"Delete", nil];
  8. alert.tag = LIST_CONFIRM_DELETE; // should use a different define (e.g. to 1) each time you use an alertview in a class, as each will call the same clickedButtonAtIndex selector.
  9. [alert show];
  10. [alert release];
  11.  
  12.  
  13. // Called when an alertview button is clicked
  14. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  15. switch (alertView.tag) {
  16. case LIST_CONFIRM_DELETE:
  17. {
  18. switch (buttonIndex) {
  19. case 0: // cancel
  20. {
  21. NSLog(@"Delete was cancelled by the user");
  22. }
  23. break;
  24. case 1: // delete
  25. {
  26. // do the delete
  27. }
  28. break;
  29. }
  30.  
  31. break;
  32. default:
  33. NSLog(@"WebAppListVC.alertView: clickedButton at index. Unknown alert type");
  34. }
  35. }
  36. }

Report this snippet  

You need to login to post a comment.