gpt4 book ai didi

ios - 尝试呈现其 View 不在窗口层次结构中的 UIViewController

转载 作者:可可西里 更新时间:2023-11-01 03:16:58 25 4
gpt4 key购买 nike

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

splash -> 导航 Controller -> table view controller -> settings view controller

Splash 是应用程序入口点,因此成为 Root View Controller 。当我尝试通过设置 View Controller 上的操作将图 block 添加到 band 时,我收到调试器警告:

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: 后立即发生。调用永远不会返回,不会产生错误。

关于如何解决这个问题有什么建议吗?

最佳答案

您将需要获取 Root View Controller 并从该 View Controller 执行 segue。调试起来可能会非常令人沮丧,但这里有一些关于这个主题的答案。

这是我用来在应用程序收到推送通知时执行从 Root View Controller 到屏幕的 segue 的一些代码。

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];

下面是 swift 中的相同代码:

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)

确保在 Storyboard中设置 View Controller 标识符。

编辑* 如果您访问的 View Controller 嵌入在导航 Controller 中,您将需要修改上述代码,

objective-c :

UIViewController *top = [self topMostController];

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

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

swift :

let top = UIApplication.shared.keyWindow?.rootViewController

let navigationController = UINavigationController.init(rootViewController: viewController)

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

关于ios - 尝试呈现其 View 不在窗口层次结构中的 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34378802/

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