Reputation: 4518
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?
Upvotes: 0
Views: 3967
Reputation: 16714
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];
Upvotes: 1