- iOS开发同时弹出多个UIAlertController
UIAlertController *alertController1 = [UIAlertController alertControllerWithTitle:@"测试1" message:@"测试1" preferredStyle:UIAlertControllerStyleAlert];
[alertController1 addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[alertController1 addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[viewController presentViewController:alertController1 animated:YES completion:nil];
UIAlertController *alertController2 = [UIAlertController alertControllerWithTitle:@"测试2" message:@"测试2" preferredStyle:UIAlertControllerStyleAlert];
[alertController2 addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[alertController2 addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}]];
[alertController1 presentViewController:alertController2 animated:YES completion:nil];
- 说明: UIAlertController继承自UIViewController,它们的页面跳转都是使用的present方法。所以,第一个UIAlertController跳转后,相当于当前最上层的页面是alertController1的页面,因此,此时想再增加一个UIAlertController,必须在alertController1上跳转。
- 注意下面两句代码中斜体字的不同:
- [viewController presentViewController:alertController1 animated:YES completion:nil];
- [alertController1 presentViewController:alertController2 animated:YES completion:nil];