美文网首页
iOS在View上显示AlertController

iOS在View上显示AlertController

作者: 遇见I你 | 来源:发表于2020-08-06 10:33 被阅读0次

    原理:

    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];
        }];
    
    

    相关文章

      网友评论

          本文标题:iOS在View上显示AlertController

          本文链接:https://www.haomeiwen.com/subject/haojrktx.html