- (IBAction)loginOut:(UIBarButtonItem *)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"确定要退出登陆吗" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定退出" otherButtonTitles:nil];
[actionSheet showInView:self.view];
} -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == ) {
//退出
[self.navigationController popViewControllerAnimated:YES];
}
}

从IOS8之后,UIAlerView和UIActionSheet 两个合并在了一起,使用了一个新的控制器UIAlertViewController,好处就是不用实现代理

UIActionSheetDelegate和UIAlerViewDelegate

UIAlertViewController使用步骤如下:

//第一步,创建控制器
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"确定退出吗" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//第二步,创建按钮
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"%s",__func__);
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
}];
//第三步,添加按钮
[alertVC addAction:action1];
[alertVC addAction:action2];
//第四步,显示弹窗,相当于show操作
[self presentViewController:alertVC animated:YES completion:nil];
05-02 00:39