Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何引用某些视图控制器_Ios_Uiviewcontroller - Fatal编程技术网

Ios 如何引用某些视图控制器

Ios 如何引用某些视图控制器,ios,uiviewcontroller,Ios,Uiviewcontroller,我正在尝试从我的应用程序委托引用UITabController,即使它不是我的rootViewController。我该怎么做 UITabBarController*tabBarController= UITabBarController*self.window.rootViewController; UINavigationController*导航控制器= [[tabBarController ViewController]对象索引:1]; DocumentsViewController*视

我正在尝试从我的应用程序委托引用UITabController,即使它不是我的rootViewController。我该怎么做

UITabBarController*tabBarController= UITabBarController*self.window.rootViewController; UINavigationController*导航控制器= [[tabBarController ViewController]对象索引:1]; DocumentsViewController*视图控制器= [[navigationController ViewController]对象索引:0]

我想更改第一行代码,使其不引用rootViewController,而是直接引用我的UITabBarController,因为我有一个要用于应用程序的开始屏幕。

在AppDelegate的.h中声明你的UITabBarController

获取对AppDelegate的引用:

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
然后你可以做:

delegate.tabBarController;
或者你可以:

[(AppDelegate*)[UIApplication sharedApplication] delegate] tabBarController];
另外,确保在rootViewController中包含AppDelegate.h/

编辑:

将其添加到rootViewController类的.h中,以便可以公开访问:

@property SecondViewController *mySecondViewController;
现在,在演示SecondViewController之前实例化SecondViewController时,请确保按照以下方式操作:

self.secondViewController = [[SecondViewController ...
self.rootViewController.mySecondViewController
现在,您应该能够从AppDelegate中引用secondViewController,如下所示:

self.secondViewController = [[SecondViewController ...
self.rootViewController.mySecondViewController

我想我不明白,也许我写得不够清楚。我的应用程序中的第一个视图是“开始”屏幕,当我单击“开始”时,它会显示我的第二个视图,它来自UITabBarController。我希望在我的应用程序委托中使用相同的代码,但不是引用rootViewController(它将是我的开始屏幕),而是要引用第二个视图,即UITabBarController。我是否应该从我的应用程序代理中引用我的应用程序代理?当在rootViewController中按start时,是否使用UINavigationController移动到secondViewController?因此secondViewController包含一个UITabBarController,您想引用第二个ViewController中包含的UITabBarController吗?很抱歉,我混淆了术语。我所说的第二个视图控制器是指通过模式连接到我的开始屏幕的视图控制器。我的第二个视图控制器是一个UITabBarController,我想从我的应用程序委托中引用它,更改那里的第一行代码。