美文网首页iOS开发iOS学习开发iOS Developer
如何在AppDelegate中弹出UIAlertControll

如何在AppDelegate中弹出UIAlertControll

作者: 老刘_Tony | 来源:发表于2016-10-13 14:30 被阅读1556次

    自从出了UIAlertController之后,我们使用弹窗口也方便了很多,在一般的控制器(Controller)中弹出弹框是很简单的,也是比较常用的,但是有的时候我们是需要在AppDelegate中就进行弹框提示操作,这个用UIAlertView来做是很容易实现的,但是对于UIAlertController中推进用的self视图控制器有的同学就不知道怎么用了,下面的代码就可以解决这个问题。

    //找到顶部视图控制器

    UIWindow  *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    alertWindow.rootViewController = [[UIViewController alloc] init];

    alertWindow.windowLevel = UIWindowLevelAlert + 1;

    [alertWindow makeKeyAndVisible];

    //初始化弹窗口控制器

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"怎么在appdelegate中弹出UIAlerController" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil];

    [alertController addAction:cancelAction];

    //显示弹出框

    [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];

    现在看是不是很简单啊。

    相关文章

      网友评论

        本文标题:如何在AppDelegate中弹出UIAlertControll

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