gpt4 book ai didi

iphone - 从 AppDelegate 获取 Storyboard定义的 UINavigationController

转载 作者:技术小花猫 更新时间:2023-10-29 11:11:22 27 4
gpt4 key购买 nike

在 Storyboard 中,我有一个介绍性的 View Controller ,它逐渐变为 UINavigationController。

      |   |      |   |
-> | | -> | |
| | | |
ViewCtrl NavCtrl

我想从应用程序委托(delegate)中获取对导航 Controller 的引用(就像@Guillaume 的回答在 this question 中所做的那样)。

这是我尝试访问它的方式:

UIApplication.sharedApplication.delegate.window.rootViewController.navigationController;

但是导航 Controller 是零。

知道为什么 navController 为 nil 或我可以做些什么来获取对它的引用吗?

最佳答案

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle: nil];

UINavigationController *controller = (UINavigationController*)[mainStoryboard
instantiateViewControllerWithIdentifier: @"<Controller ID>"];

您在导航 Controller 的属性检查器中指定导航 Controller 的 Controller 标识符。

关于iphone - 从 AppDelegate 获取 Storyboard定义的 UINavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18389029/

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