uialertview在ios9中的使用

iOS9中改变了UIAlertView的使用方式, 并且与UIActionSheet融合进了一个类里面,统一进行管理.


- (void)loginOut
{
// 1.创建一个alertController来管理警示窗口, 并指定样式
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"确定注销吗?" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
// 2.创建点击行为, 在block中实现事件
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
NSLog(@"已注销");
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"取消注销");
}];
// 3.为alertController添加点击行为
[alertController addAction:action];
[alertController addAction:cancel];
// 4.弹出警示窗口
[self presentViewController:alertController animated:YES completion:nil];
}