我有一个webview,可以加载允许用户上传图片的页面。当用户选择“拍照”选项时,应用程序会崩溃,并显示以下警告。
警告:尝试在视图不在窗口层次结构中的<UIImagePickerController: 0x1563d8000>
上显示<UINavigationController: 0x156b4c400>
!
以下是用于加载webview的代码
WebViewController *webViewController = [[WebViewController alloc] initWithUrlString:urlString];
[viewController showViewControllerFullScreen:webViewController];
- (void)showViewControllerFullScreen:(UIViewController *)viewController {
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.view.window.rootViewController presentViewController:navigationController animated:YES completion:nil];
}
为什么UINavigation Controller在用于呈现Web视图时不属于窗口层次结构?
答案 0 :(得分:0)
请设置以下行
self.window.rootViewController = navigationController;
参考
UIImagePickerController on UINavigationController whose view is not in the window hierarchy
iOS: Warning “attempt to present ViewController whose view is not in the window hierarchy”