尝试提供一个UIViewController,其视图不在窗口层次结构中 [英] Attempt to present a UIViewController whose view is not in the window hierarchy

查看:181
本文介绍了尝试提供一个UIViewController,其视图不在窗口层次结构中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下层次结构的多视图应用程序:

I have a multi-view application with the following hierarchy:

启动->导航控制器->表格视图控制器->设置视图控制器

splash -> navigation controller -> table view controller -> settings view controller

Splash是应用程序的入口点,因此成为根视图控制器.当我尝试通过设置视图控制器上的操作向区域添加平铺时,收到调试器警告:

Splash is the application entry point and therefore becomes the root view controller. When I try to add a tile to the band via an action on the settings view controller, I get a debugger warning:

application [1929:1000746]警告:尝试呈现< MSBAddTileDialogViewController_iOS:0x15f0575b0>在< SplashViewController:0x15dd597b0>上其视图不在窗口层次结构中!

application[1929:1000746] Warning: Attempt to present <MSBAddTileDialogViewController_iOS: 0x15f0575b0> on <SplashViewController: 0x15dd597b0> whose view is not in the window hierarchy!

这在调用MSBClient.tileManager addTile:completionHandler:之后立即发生.呼叫永不返回,不会产生错误.

This happens immediately after the call to MSBClient.tileManager addTile:completionHandler:. The call never returns, no error is generated.

关于如何解决此问题的任何建议?

Any suggestions on how to get around this?

推荐答案

您将需要获取根视图控制器并从该视图控制器执行segue.调试起来可能很令人沮丧,但是这里有关于此主题的一些答案.

You will need to get the root view controller and perform a segue from that view controller. This can be quite frustrating to debug but there are some answers on here about this topic.

当应用程序收到推送通知时,我使用了一些代码从根视图控制器到屏幕执行了搜索.

Here is some code that I have used to perform a segue from the root view controller to a screen when the app receives a push notification.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YourStoryboard" bundle:nil];

YourViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"viewcontrolleridentifier"];

UIViewController *top = [UIApplication sharedApplication].keyWindow.rootViewController;

[top presentViewController:viewController animated:YES completion: nil];

迅速找到相同的代码:

let storyboard = UIStoryboard.init(name: "YourStoryboard", bundle: nil)

let viewController = storyboard.instantiateViewController(withIdentifier: "viewcontrolleridentifier")

let top = UIApplication.shared.keyWindow?.rootViewController

top?.present(viewController, animated: true, completion: nil)

确保在情节提要中设置视图控制器标识符.

Make sure you set the view controllers identifier in your storyboard.

编辑*如果要访问的视图控制器嵌入在导航控制器中,则需要修改以上代码,

EDIT* If the view controller you are accessing is embedded within a navigation controller you will need to amend the above code,

目标C:

UIViewController *top = [self topMostController];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

[top presentViewController:navigationController animated:YES completion: nil];

迅速:

let top = UIApplication.shared.keyWindow?.rootViewController

let navigationController = UINavigationController.init(rootViewController: viewController)

top?.present(navigationController, animated: true, completion: nil)

这篇关于尝试提供一个UIViewController,其视图不在窗口层次结构中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆