简体   繁体   中英

iOS: Accessing Navigation View Controller From AppDelegate

How to access navigation controller from the AppDelegate?

Suppose I have the following viewControllers:

NavViewController -> UIViewController -> NavViewController -> UIViewController -> NavViewController -> UITableViewController

In AppDelegate.m, how can I access the UITableViewController?

I just know how to access the first ViewController using the below code:

UINavigationController *navigationController = (UINavigationController)[self.window.rootViewController navigationController];
UIViewController *viewController1 = (UIViewController)[navigationController viewControllers]objectAtIndex:0];

but can someone teach me how to access the UITableViewController and the second UIViewController From the AppDelegate.m?

NavViewController -> UIViewController -> NavViewController -> UIViewController -> NavViewController -> UITableViewController

You should never have this. I don't even know if this is possible. You should only have ONE UINavigationController. Maybe you were just displaying your setup in an odd way.

You could access the second UIViewController from the app delegate like this:

UIViewController *viewController2 = (UIViewController *)[navigationController viewControllers]objectAtIndex:1];

And the UITableViewController like this:

UITableViewController *viewController3 = (UITableViewController *)[navigationController viewControllers]objectAtIndex:2];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM