當前位置:
首頁 > 知識 > whose view is not in the window hierarchy的解決辦法

whose view is not in the window hierarchy的解決辦法

場景:模態跳轉的時候,做提示框UIAlertController 寫在viewDidLoad中就會不出現提示框,且出現如下警告:

whose view is not in the window hierarchy的解決辦法

解決辦法:

你可以把這段代碼放入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];

這樣子就可以了

whose view is not in the window hierarchy的解決辦法

喜歡這篇文章嗎?立刻分享出去讓更多人知道吧!

本站內容充實豐富,博大精深,小編精選每日熱門資訊,隨時更新,點擊「搶先收到最新資訊」瀏覽吧!


請您繼續閱讀更多來自 程序員小新人學習 的精彩文章:

高並發之緩存的特徵和應用
代碼生成x264編碼flv記錄

TAG:程序員小新人學習 |