Reputation: 310
I want a global navigation stack. When the user changes tabs or navigates to a new view in the same tab, I want to push the new view onto the global navigation stack. I want the back button in the navigation bar to go back to the previous view, which is sometimes a different tab, and sometimes a different view in the same tab.
Upvotes: 5
Views: 435
Reputation: 5105
I got it working. In my experience I was needed to have mainTabBarController
and detailedNavigationController
as two root controllers.
Those two methods of UIApplicationDelegate
class work perfect:
- (void) showDetailedTab
{
CGRect normalRect = self.window.bounds;
CGRect rightRect = CGRectOffset(normalRect, normalRect.size.width, 0);
CGRect leftRect = CGRectOffset(normalRect, -normalRect.size.width, 0);
detailedNavigationController.view.frame = rightRect;
mainTabBarController.view.frame = normalRect;
[self.window addSubview:mainTabBarController.view];
[self.window addSubview:detailedNavigationController.view];
[UIView animateWithDuration:0.35 delay:0.0 options:UIViewAnimationCurveEaseOut
animations: ^{
detailedNavigationController.view.frame = normalRect;
mainTabBarController.view.frame = leftRect;
}
completion: ^(BOOL finished){
[mainTabBarController.view removeFromSuperview];
}];
}
- (void) showMainTabBar
{
CGRect normalRect = self.window.bounds;
CGRect rightRect = CGRectOffset(normalRect, normalRect.size.width, 0);
CGRect leftRect = CGRectOffset(normalRect, -normalRect.size.width, 0);
mainTabBarController.view.frame = leftRect;
detailedNavigationController.view.frame = normalRect;
[self.window addSubview:mainTabBarController.view];
[self.window addSubview:detailedNavigationController.view];
[UIView animateWithDuration:0.35 delay:0.0 options:UIViewAnimationCurveEaseOut
animations: ^{
mainTabBarController.view.frame = normalRect;
detailedNavigationController.view.frame = rightRect;
}
completion: ^(BOOL finished){
[detailedNavigationController.view removeFromSuperview];
}];
}
I think this solution is better then emulating of tab bar, since it doesn't break UIViewContoller
's life cycle.
Upvotes: 0
Reputation: 31722
you could achieve the same by setting the left bar button of your UINavigationController
as the button of your choice, Handle the action method and invoke the appropriate tabbar button on click event.
You need to do all that in your root view controller ...
ADDED:
You could not get the back button on the root view controllers (Navigation controllers;s root view associated with your tabbar instance) just by pressing the tabbar button.
you need to find the way to achieve this as you are not getting this from iOS So The movement you press the tabbar button your need to have the variable that store the previous selected index and a method that give the information for any tabbar by just passing the index ... So by using these two you could set the title of your left bar button of navigation bar and return to the previous tab by assigning the appropriate action method to the left bar button ...
Upvotes: 0
Reputation: 11970
To achieve this effect, you could ditch the UITabBarController - and emulate the bar by using a custom view or customizing the standard UIToolbar.
Have one navigation controller with, with your customized toolbar always visible, and when buttons are tapped on it, just push the views you want onto the navstack.
Upvotes: 4
Reputation: 19418
I Had similar issue. I did it like this :
To change the tab, use : say, you want to go at tab 2 and its 3rd view controller
self.tabBarController.selectedIndex = 2;
[self.tabBarController.delegate tabBarController:self.tabBarController didSelectViewController:
[[[self.tabBarController.viewControllers objectAtIndex:2] viewControllers] objectAtIndex:3]];
Upvotes: 0
Reputation: 16719
I suggest you to create a global array (NSMutableArray) that will hold NSInvocation objects. So every time you push view controller you need to create NSInvocation with navigation controller as target and popViewConrollerAnimated:
as selector. If you're tapping the tab bar item you need to set tab bar controller as target and setSelectedViewController:
as selector. You should also specify current view controller as parameter using
- (void)setArgument:(void *)buffer atIndex:(NSInteger)index
Then every time you pop your global stack you need just call [myLastInvocation invoke]
;
Upvotes: 0
Reputation: 4546
You want all the UIViewController
's in the UITabBarController
to be loaded into the same UINavigationController
?
So something like this:
___ RootViewController ___
| |
UINavigationController UITabBarViewController
instead of
RootViewController
|
_________ UITabbarViewController _____________________
| | |
UINavigationController UINavigationController UINavigationController
You should try "experimenting" with your own custom UITabBar
Upvotes: 0