swift - 如何检索嵌入在 NavigationViewController 中的 rootViewController?

标签 swift

我有一个 View Controller 作为 TabBar 的第一个 ViewController,当我必须从应用程序委托(delegate)调用它时一切正常。

let homeVC = ((window?.rootViewController as! UITabBarController).viewControllers![0]) as! GardenViewController

现在我添加了一个 NavigationController 但我不知道如何访问我的 viewController (GardenViewController)。 我尝试了一切,但似乎没有任何效果。 有想法吗?

最佳答案

试试这个:

let navigationVC = ((window?.rootViewController as! UITabBarController).viewControllers![0]) as! UINavigationController
let homeVC = navigationVC.viewControllers[0] as! GardenViewController

关于swift - 如何检索嵌入在 NavigationViewController 中的 rootViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49032829/

相关文章:

swift - 如何在枚举 Swift 3.0 中访问和创建函数

ios - 是否可以强制 iOS 设备以编程方式从所述应用程序打开/切换到我的应用程序?

ios - UICollectionViewCell 与异步图像重用加载错误图像

ios - INVoiceShortcutCenter.shared.setShortcutSuggestions(suggestions) 在 iOS 13 Beta 中崩溃。 Xcode 11 测试版

swift 。如何允许将 URL 从浏览器拖动到 NSView

swift - 快速将 UIImage 更改为数组或矩阵

ios - UITableView 标题背景颜色没有完全改变

ios - 在单独的类中实现 CLLocationManagerDelegate 时出现内存错误

Swift - 如何在一群人之间平均分配一笔钱?

ios - UISearchBar 范围空白