PopToRootViewController按第3级,没有弹出按钮项目

时间:2010-11-01 19:41:30

标签: uinavigationcontroller iphone rootview

我正在使用我的UINavigationController推动一些viewcontrollers,当我在我的第三个UISubViewController上时,我编码为'popToRootViewController'并且它弹出后面,导航栏项目推送到第二个查看控制器不到第一..

  • 我尝试使用和不使用动画,但没有任何改变。
  • 我试图说self.navigationController.navigationBar弹回,但它在我的栏上什么也没做。

感谢您的帮助..

2 个答案:

答案 0 :(得分:1)

我对你的问题有点困惑,但我认为这应该有所帮助。据我所知,你不能在UINavigationController上使用“后退”按钮返回超过1个pop。所以你要做的就是添加另一个执行popToRootViewController功能的按钮。尝试这样的事情:

UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStylePlain target:self action:@selector(homeAction:)];

self.navigationItem.rightBarButtonItem = newButton;

这将在导航控制器的右侧添加一个按钮。下一步是在动作中添加一个名为您名字的函数(在这种情况下,它需要被称为“homeAction”)。这看起来像这样:

-(IBAction)homeAction:(id)sender {
      [self.navigationController popToRootViewControllerAnimated:YES];
}

这应该涵盖弹出回到控制器根目录的位置。您还需要将IBAction方法用于.h文件,但除此之外,它应该执行您想要的所有操作。

答案 1 :(得分:0)

除非你在NavigationController上使用View Controllers数组做一些奇怪的事情,否则方法应该是:

[self.navigationController popToRootViewControllerAnimated:YES];