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.
In the applicationDelegate.h we have:
UINavigationController *navController;
And the following in applicationDelegate.m
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window addSubview: navController.view];
[window makeKeyAndVisible];
}
Is there anyway to get the navController from the mainWindow:
UIWindow *mainWindow = [appDelegate window];
If this other UIViewController is contained in the UINavigationController, you can simply call:
UINavigationController *navController = self.navigationController;
from the UIViewController.
Otherwise, you can set UINavigationController as a property in the AppDelegate.
// AppDelegate.h
@property (nonatomic, strong) UINavigationController *navController;
Then access appDelegate.navController
.
Or, you can set the UINavigationController as window's rootViewController:
[window setRootViewController:navController];
And call from anywhere:
UINavigationController *navController = window.rootViewController;
You can make the navController a property
@property (nonatomic,strong) UINavigationController *navController;
Then just access it from your appdelegate
appDelegate.Controller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With