【问题标题】:iPhone/iOS: Push Controller onto NavigationController that is currently not selectediPhone/iOS:将控制器推送到当前未选中的 NavigationController
【发布时间】: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


【解决方案1】:

尝试做

[appDelegate.firstnavigationcontroller pushViewController:controllerToPush animated:YES];

【讨论】:

  • 不,对我不起作用。你试过了吗,还是只是猜测?
  • 只是猜测。但是我以前遇到过这种情况。但是现在我不在我的mac前引用我使用的代码。 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-02
  • 1970-01-01
  • 1970-01-01
  • 2020-03-29
相关资源
最近更新 更多