bugfixr
bugfixr

Reputation: 8077

Access a Navigation controller's main view programmatically

I've got a Tab Controller with a navigation controller which has a view, as seen in the image below:

Screen shot of Main.XIB

I need to retrieve the Switches Controller from within my AppDelegate so I can do some things with it at runtime.

I believe I can retrieve the NavigationController itself by doing this:

UINavigationController *navController = [tabBarController.viewControllers objectAtIndex:0]; 

Not really sure how to access my SwitchesController from there though. Any suggestions?

Upvotes: 0

Views: 219

Answers (2)

Paul.s
Paul.s

Reputation: 38728

Why not make an ivar with an IBOutlet? It's probably the most flexible solution as you can now change the ordering of your viewController's without breaking your build.

Upvotes: 1

user529758
user529758

Reputation:

Use one of the visibleViewController, topViewController properties of UINaviationController, or call:

[navigationController.viewControllers objectAtIndex:index];

Docs: http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

Hope it helps.

Upvotes: 0

Related Questions