Reputation: 6769
I'm planning with my App to have a root UIViewController
in the App Delegate, that basically branches off into a possible two UIViewControllers
, each of those UIViewControllers
will have a number of UINavigationControllers
pushed onto of them, might have a UITabBarController
, not too sure yet but the main issue is I want to from any view transfer from one UIViewController
stack to the other, and maintain the view hierarchy.
When I want to change from one UIViewController
stack to the other, I thought about calling the App delegate:
MainClass *appDelegate = (MainClass *)[[UIApplication sharedApplication] delegate];
[appDelegate.viewController someMethod];
and transitioning that way, but it seems a bit of a hacky way to do it. Also thought about passing a reference through the stack to the root UIViewController
and call the method to change between the UIViewControllers
.
Which way would be the better way? Or is there a way I haven't thought about that is the preferred way of doing it?
Upvotes: 0
Views: 210
Reputation: 5616
A UITabBarController
offers you exactly that functionality. If you have one as your root view controller and two tabs with a navigation controller in each tab, then you're basically done. If you don't want to show the tab bar in the bottom you can just hide it and then trigger the tab switch from code following some events. It's pretty straight forward :)
Upvotes: 1
Reputation: 536
do you mean you have one root view controller and this root VC manages two view controllers and these two controllers manages many sub view controllers?
if so, you may try to use custom containment controller. and every time you want to change stack from one to another, just delegate to rootVC to do so.
- (void)moveToAnotherController:(UIViewController *)vc
{
[self displayContentController:vc];
}
- (void)displayContentController:(UIViewController *)content
{
[self addChildViewController:content];
[self.view addSubview:content.view];
[content.view setFrame:self.view.bounds];
[content didMoveToParentViewController:self];
}
//remove child controller from container
- (void)hideContentController:(UIViewController *)content animated:(BOOL)animated
{
[content willMoveToParentViewController:nil];
[content.view removeFromSuperview];
[content removeFromParentViewController];
}
Upvotes: 1