gpt4 book ai didi

ios - 修复警告 : Attempt to present ViewController on NavigationController whose view is not in the window hierarchy

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:18:11 25 4
gpt4 key购买 nike

目前,我已经为我的应用程序的用户设置了一个登录 View 。下面是向用户显示此登录 View 的代码:

 // Handle how we present the view
if (self.notificationToProcess != nil) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
SWNotificationsViewController *viewController = [[NotificationsViewController alloc] init];
viewController.initialDataID = self.notificationToProcess[@"Data"];
self.notificationToProcess = nil;

[self.navigationController pushViewController:viewController animated:YES];
}];
} else if (self.detailURL != nil) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
WebViewController *wvc = [[WebViewController alloc] init];
wvc.URL = self.detailURL;
wvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:wvc animated:YES completion:nil];

self.detailURL = nil;
}];
} else {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

我现在尝试做的是,如果用户刚刚更新了应用程序,则首先显示 WebView 。下面是这段新代码的样子:

// Handle how we present the view.
if (self.notificationToProcess != nil) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
SWNotificationsViewController *viewController = [[SWNotificationsViewController alloc] init];
viewController.initialDataID = self.notificationToProcess[@"Data"];
self.notificationToProcess = nil;

[self.navigationController pushViewController:viewController animated:YES];
}];
} else if (self.detailURL != nil) {
[self.navigationController dismissViewControllerAnimated:YES completion:^{
SWWebViewController *wvc = [[SWWebViewController alloc] init];
wvc.URL = self.detailURL;
wvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:wvc animated:YES completion:nil];

self.detailURL = nil;
}];
else if (![versionOfLastRun isEqual:currentVersion])
{
SWWebViewController *webViewController = [[SWWebViewController alloc] init];
NSString *url=@"http://someurl";
webViewController.URL = url;
webViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:webViewController animated:YES completion:nil];
[[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:@"VersionOfLastRun"];
[[NSUserDefaults standardUserDefaults] synchronize];

}
else if (versionOfLastRun == nil){
// First start after installing the app
}

else {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

但是,当我运行该应用程序时,未显示 Web View ,我收到以下警告:

警告:尝试在其 View 不在窗口层次结构中的 NavigationController 上呈现 ViewController!

任何人都可以帮助我诊断问题吗?谢谢!

最佳答案

似乎您的 viewController 不在导航 Controller 层次结构中。这意味着您的 Controller 未与应处理所呈现 Controller 的导航 Controller 堆栈连接。

另一件应该有帮助的事情是设置你的 Root View Controller 如下:

self.window.rootViewController = self.ViewController;

编辑:因为您提到您不使用 Storyboard ,设置 rootViewController 应该可以解决问题。

关于ios - 修复警告 : Attempt to present ViewController on NavigationController whose view is not in the window hierarchy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28152881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com