在appdelegate中弹出控制器

自从出了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];

现在看是不是很简单啊。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容