在AppDelegate中使用UIAlertController提示框
关于AppDelegate.m中无法使用UIAlertController
不喜欢UIAlertController,也可以自定义的。
//初始化UIAlertController
UIAlertController *alertCtl = [UIAlertController alertControllerWithTitle:@"提示" message:@"AppDelegate中" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *SureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"确定点击了");
}];
UIAlertAction *CancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"取消点击了");
}];
[alertCtl addAction:SureAction];
[alertCtl addAction:CancelAction];
//初始化UIWindows
UIWindow *newWindow= [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
newWindow.rootViewController = [[UIViewController alloc]init];
newWindow.windowLevel = UIWindowLevelAlert + 1;
[newWindow makeKeyAndVisible];
[newWindow.rootViewController presentViewController:alertCtl animated:YES completion:nil];
网友评论