Within my iPhone App I use a UITabBarController that holds four UINavigationController. Each UINavigationController represents a specific navigation within my app.
Normally if I want to push a new controller onto the stack of the current UINavigationController I just do something like:
// push another controller onto the current NavigationController Stack
MyController* controllerToPush = [[MyController alloc]init];
[self.navigationController pushViewController:controllerToPush animated:YES];
[controllerToPush release];
However there are a few places within my app, where the user is located within on navigationController and his action should change the selected Tab of the UITabBarController and push the controller there. I tried something like:
// Get a reference to my appDelegate
MyAppDelegate*开发者_高级运维 appDelegate = [[UIApplication sharedApplication] delegate];
// Change the selected Index of my TabBarController
[[appDelegate tabBarController] setSelectedIndex:0];
// Get a reference to the NavigationController whose Index within the TabBarController is 0
UINavigationController* navigationController = [appDelegate firstNavigationController];
// Push the newly initiliazed controller onto the navigationController
MyController* controllerToPush = [[MyController alloc]init];
[navigationController pushViewController:controllerToPush animated:YES];
[controllerToPush release];
But this approach doesnt work. The selectedIndex of the TabBar chances correctly, but the controllerToPush has not been added to the navigationController-Stack. What am I doing wrong?
Try doing
[appDelegate.firstnavigationcontroller pushViewController:controllerToPush animated:YES];
精彩评论