【发布时间】:2011-05-29 17:26:24
【问题描述】:
在我的 iPhone 应用程序中,我使用了一个包含四个 UINavigationController 的 UITabBarController。每个 UINavigationController 代表我的应用程序中的特定导航。
通常,如果我想将新控制器推送到当前 UINavigationController 的堆栈中,我只需执行以下操作:
// push another controller onto the current NavigationController Stack
MyController* controllerToPush = [[MyController alloc]init];
[self.navigationController pushViewController:controllerToPush animated:YES];
[controllerToPush release];
但是,在我的应用程序中有几个地方,用户位于 navigationController 上,他的操作应该更改 UITabBarController 的选定选项卡并将控制器推到那里。我试过类似的东西:
// 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];
但是这种方法行不通。 TabBar 的 selectedIndex 机会正确,但 controllerToPush 尚未添加到 navigationController-Stack。我做错了什么?
【问题讨论】:
-
你确定
appDelegate.firstNavigationController不为零吗? -
您能否提供更多来自 Application Delegate 的代码?
标签: iphone uinavigationcontroller uitabbarcontroller