1
votes

I have a tab bar application. One of the tabs has a navigation stack. I would like to change tabs programatically and then push a new controller onto the selected tabs stack. I can change tabs fine:

   KidScienceAppDelegate *appDelegate = (KidScienceAppDelegate*) [[UIApplication sharedApplication] delegate];
    UITabBarController *tab=[appDelegate tabBarController] ;
    tab.selectedIndex=2;

If I just run that, it properly move to the tab with the navigation stack and shows the root view. I'd like to then push a new controller onto that stack. I've tried this:

ExperimentsNameViewController *detailViewController = [[ExperimentsNameViewController alloc] initWithNibName:@"ExperimentsNameView" bundle:nil];

FindViewController *c = [tab.viewControllers objectAtIndex:2];
[c.navigationController pushViewController:detailViewController animated:NO];

but this doesn't push the controller. Anyone have any thoughts?

1

1 Answers

1
votes

If you have a navigation controller at index 2, you will get a navigation controller when you do [tab.viewControllers objectAtIndex:2]; so it should be

[..]
UINavigationController * navigationController = [tab.viewControllers objectAtIndex:2];
[navigationController pushViewController:detailViewController animated:NO];