【发布时间】:2018-03-02 04:56:58
【问题描述】:
我有一个UINavigationController 作为rootViewController,它最终将UITabBarController 推到堆栈的顶部。
UITabBarController 有 2 页。每个页面都有UINavigationController作为根,假设这是UINavigationController A和B。
A 和 B 都有一个 UIViewController 作为根。假设这是 C 和 D。
现在我正在编写 UIViewController C 类。我想从 C 中获得对 UITabBarController 的引用。所以我这样做了:
self.tabBarControllerself.navigationController?.tabBarController
所有这些都返回零。如何获取对UITabBarController 对象的引用?
【问题讨论】:
-
您试图在视图控制器的哪个位置访问选项卡控制器?如果在正确的地方调用,你的两种尝试都应该有效。
-
发布你将控制器 C 添加到 UITabBarController 的代码
-
@rmaddy 是的,从我在互联网上阅读的内容来看,应该是,但令人惊讶的是,我的两个代码都为零。
-
@IraniyaNaynesh 我使用故事板将
UINavigationControllers和UIViewControllers放入UITabBarController。 -
@ChenLiYong 你没有回答我的问题。这段代码在哪里?
标签: ios swift uiviewcontroller uinavigationcontroller uitabbarcontroller