Reputation: 1655
I have a Tab bar Controller containing 5 Tabs and each tab bar item has individual navigation controller like :
Now , If i am currently in viewctrller3 of navigationctrller3 in Tab3 and i want to navigate to viewctrller2 of navigationctrller1 in Tab1 programmatically . Also I've selected the particular Tab1 programmatically But i m unable to reach viewctrller2 of navigationctrller1. Is this feasible ?, If yes , then please elaborate.. Please guys join hands..!
Upvotes: 2
Views: 2805
Reputation: 104082
If you are currently in viewctrller3, I think you should be able to do this:
UITabBarController *tabCont = (UITabBarController *)[self.navigationController parentViewController];
[tabCont setSelectedIndex:0];
UINavigationController *nav1 = tabCont.selectedViewController;
NSarray *newControllers = [NSArray arrayWithObjects:[nav1.viewControllers objectAtIndex:2],[nav1.viewControllers objectAtIndex:0],[nav1.viewControllers objectAtIndex:1], nil];
[nav1 setViewcontrollers:newControllers animated:NO];
That last line should rearrange the navigation controller's viewControllers so that viewctrller2 is now the top view controller.
Upvotes: 3
Reputation: 1838
One way to achieve this is
(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
check whether the visible controller is kind of class same as the class name that is set in appdelegate reference variable? If yes then nothing to do , if not then check if that controller is in the navigation stack or not? If its there in stack then pop/push to that index controller else create that controller and push to it.Upvotes: 0
Reputation: 4249
From ViewController3 execute..
UINavigationController *navigationController1 = [appDelegate.tabBarController.viewControllers objectAtIndex:2]; // fetch the navigationController
[navigationController1 popToViewController:[navigationController1.viewControllers objectAtIndex:1] animated:NO];
[appDelegate .tabBarController setSelectedIndex:0];
Upvotes: -1
Reputation: 3580
I dont think that there will be any issue in this. suppose your nav1 is 1st navigationController.
[self.nav1 pushViewController:view2 animated:YES];
its will have to work for you.
Upvotes: -1