Reputation: 2284
In my iPhone app, I have used tabbarcontroller in that i have 4 tabs for four different items
In each tab i have different views navigate transaction in those.
my requirement is, when i switch form on tab to another tab by taping on tabbar item.
T*the main view (first view ) of each tab has to be appeared instead of currently working view.
*
For ex:
I select tab 3 there i do some operations and navigate to some 2nd view in the third tab.
and then i secet tab 4 and then again tab3.. then the previously woriking view view 2 presents in tab3,
how to do..
Upvotes: 0
Views: 93
Reputation: 104082
Make a subclass of UINavigationController, change the class of any navigation controllers you have in your storyboard to that class, and put this code in that subclass:
-(void)viewDidDisappear:(BOOL)animated {
[self popToRootViewControllerAnimated:NO];
}
Whenever you click on another tab, this method will be called, and it will reset the navigation stack back to the root view controller.
Upvotes: 3
Reputation: 2270
Set your view controller or appdelegate as delegate of your tabbarcontroller. implement this delegate function
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
int selectedIndex = tabBarController.selectedIndex;
NSArray *tabbarControllers = tabBarController.viewControllers;
//Then replace tabbarControllers[selectedIndex] by your new view controller(with navigation controller)
tabBarController.viewControllers = Your replaced Array;
}
Upvotes: 0