13 Feb 2012

iOS通过UIActionSheetDelegate来实现警告的方法

Share

有时候需要用户确认一些操作,比如退出,删除数据等等,用UIActionSheetDelegate实现比较友好,实现也很简单,controller实现UIActionSheetDelegate协议就可以了,示例如下:

01 #pragma mark-
02 #pragma mark UIActionSheetDelegate with logOff
03
04 - (void) onLogOffButtonClick:(id)sender{
05     UIActionSheet actionSheet = [[UIActionSheet alloc] initWithTitle:@“确认要退出登录吗?” delegate:self cancelButtonTitle:@“不退出” destructiveButtonTitle:@“退出” otherButtonTitles:nil, nil];
06    
07     [actionSheet showFromTabBar:self.navigationController.tabBarController.tabBar];
08     XX_RELEASE_SAFELY(actionSheet);
09 }
10 - (void)logOff{
11
12     //do logoff
13    
14     [self.navigationController popViewControllerAnimated:YES];
15 }
16
17 - (void)actionSheet:(UIActionSheet
)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex; {
18     switch (buttonIndex) {
19         case 0:
20             [self logOff];
21             break;
22         case 1:
23             [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
24             break;
25         default:
26             break;
27     }
28 }

comments powered by Disqus