如何从AppDelegate获取navController。 [英] How to get navController from AppDelegate.

查看:444
本文介绍了如何从AppDelegate获取navController。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在iPhone编程中从 AppDelegate = [[UIApplication sharedApplication] delegate] 获取navController。例如,在我们引用AppDelegate的其他viewController中。

I am wondering, that how to get navController from AppDelegate = [[UIApplication sharedApplication] delegate] in the iPhone programming. e.g., in other viewController where we reference to the AppDelegate.

在applicationDelegate.h中我们有:

In the applicationDelegate.h we have:

UINavigationController *navController;

以下是applicationDelegate.m

And the following in applicationDelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

   [window addSubview: navController.view];
   [window makeKeyAndVisible];
}

无论如何从mainWindow获取navController:

Is there anyway to get the navController from the mainWindow:

UIWindow *mainWindow = [appDelegate window];


推荐答案

如果其他UIViewController包含在UINavigationController中,可以简单地调用:

If this other UIViewController is contained in the UINavigationController, you can simply call:

UINavigationController *navController = self.navigationController;

否则,您可以将UINavigationController设置为AppDelegate中的属性。

Otherwise, you can set UINavigationController as a property in the AppDelegate.

// AppDelegate.h
@property (nonatomic, strong) UINavigationController *navController;

然后访问 appDelegate.navController

或者,您可以将UINavigationController设置为窗口的rootViewController:

Or, you can set the UINavigationController as window's rootViewController:

[window setRootViewController:navController];

从任何地方拨打电话:

UINavigationController *navController = window.rootViewController;

这篇关于如何从AppDelegate获取navController。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆