如何在AppDelegate上从TabBarController获取ViewController? [英] How can I get ViewController from TabBarController on AppDelegate?
问题描述
我使用iOS5故事板,而我的初始视图控制器是 TabBarController
,view1& view2& view3& view4,那么,我怎样才能获得view3的视图控制器?
I use iOS5 storyboard, and my initial view controller is TabBarController
, there are four relationships to view1 & view2 & view3 & view4, so, how can I get the view3's view controller?
我试过:
[[[[self.window.rootViewController navigationController] tabBarController] viewControllers] objectAtIndex:2];
但它不起作用......
But it doesn't work...
推荐答案
你说你的初始(根)视图控制器是一个UITabBarController,但你指的是带有带标签栏控制器的导航控制器的视图控制器。您是否在视图控制器层次结构中混淆了?
You said that your initial (root) view controller is a UITabBarController but you are referring to a view controller with a navigation controller with a tab bar controller. Are you getting mixed up in your view controller hierarchy?
编辑:
如果您的根视图控制器实际上只是一个标签栏控制器并且您想获得第三个选项卡是代码:
if your root view controller is actually just a tab bar controller and you want to get the 3rd tab here is the code:
[[((UITabBarController *)self.window.rootViewController) viewControllers] objectAtIndex:2];
这篇关于如何在AppDelegate上从TabBarController获取ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!