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];
属于一个开发中的小知识,希望对有需要的人帮助~
网友评论