原理:
1.创建一个 ViewController 对象为 tempVc ;
2.将 tempVc.view 添加到需显示 AlertController 的 View 上 ;
3.用 presentViewController: animated: completion: 显示 ;
实现:
UIAlertController *alvc = [UIAlertController alertControllerWithTitle:@"标题" message:nil preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"重试" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"回调方法 ----- kkkk");
}];
[alvc addAction:confirmAction];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"挂断" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"回调方法 ----- kkkk");
}];
[alvc addAction:cancelAction];
UIViewController *tempVc = [[UIViewController alloc] init];
[self addSubview:tempVc.view];
[tempVc presentViewController:alvc animated:YES completion:^{
[tempVc.view removeFromSuperview];
}];
网友评论