iPhone: Use UIAlertView to confirm a deletion


/ Published in: Objective C
Save to your folder(s)

You must add UIAlertViewDelegate to the protocols for your class


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.