美文网首页
在UIView上弹出UIAlertController

在UIView上弹出UIAlertController

作者: 爱吃萝卜的小蘑菇 | 来源:发表于2019-03-05 11:39 被阅读0次

创建一个UIViewController,将其view添加到需要显示UIAlertControllerview上,然后用UIViewController显示

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"设置别名不得超过三个字" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:confirmAction];
    //创建用于显示alertController的UIViewController
    UIViewController *alertVC = [[UIViewController alloc]init];
    [self addSubview:alertVC.view];
    [alertVC presentViewController:alertController animated:YES completion:^{
      //移除用于显示alertController的UIViewController
      [alertVC.view removeFromSuperview];
    }];

相关文章

网友评论

      本文标题:在UIView上弹出UIAlertController

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