(IOS)在非ViewController的地方弹出UIAlertController对话框

//  最好抽成一个分类

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];

//...

id rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;

if([rootViewController isKindOfClass:[UINavigationController class]])

{

    rootViewController = ((UINavigationController *)rootViewController).viewControllers.firstObject;

}

if([rootViewController isKindOfClass:[UITabBarController class]])

{

    rootViewController = ((UITabBarController *)rootViewController).selectedViewController;

}

[rootViewController presentViewController:alertController animated:YEScompletion:nil];

你可能感兴趣的:((IOS)在非ViewController的地方弹出UIAlertController对话框)