AppDelegate中弹出UIAlertController

iOS8之后提示框都使用UIAlertController,在UIViewController中调用也比较简单,但是如果我们在AppDelegate中使用UIAlertController每天直接调用,需要一点小技巧来解决这个问题:
1.初始化UIAlertController:

        UIAlertController *alertController=[UIAlertController alertControllerWithTitle:title message:content preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            NSLog(@"简书-FlyElephant");
        }];
        [alertController addAction:sureAction];

2.初始化UIWindow:

        UIWindow   *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
        alertWindow.rootViewController = [[UIViewController alloc] init];
        alertWindow.windowLevel = UIWindowLevelAlert + 1;
        [alertWindow makeKeyAndVisible];
        [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];

属于一个开发中的小知识,希望对有需要的人帮助~

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

推荐阅读更多精彩内容