whose view is not in the window hierarchy的解決辦法
場景:模態跳轉的時候,做提示框UIAlertController 寫在viewDidLoad中就會不出現提示框,且出現如下警告:
解決辦法:
你可以把這段代碼放入viewDidAppear裡邊,但是我覺得你獲取到當前控制器更好:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"溫馨提示" message:@"sdsdfsdf" preferredStyle: UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleCancel handler:nil]];
UIViewController *topRootViewController = [[UIApplication sharedApplication] keyWindow].rootViewController;
// 循環
while (topRootViewController.presentedViewController)
{
topRootViewController = topRootViewController.presentedViewController;
}
// 然後再進行present操作
[topRootViewController presentViewController:alert animated:true completion:nil];
這樣子就可以了
TAG:程序員小新人學習 |