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

发布于 2024-09-30 08:16:19 字数 290 浏览 1 评论 0原文

我用 UINavigationController 推送到一些视图控制器,当我在第三个 UISubViewController 上时,我编码为“popToRootViewController”,它弹出回来,但是导航栏项目推送到第二个视图控制器没有到第一个..

  • 我尝试了带动画和不带动画的方法,但什么都不会改变。
  • 我试图说 self.navigationController.navigationBar 弹出回来,但它对我的栏没有任何作用。

谢谢你的帮助..

I'm pushing to a few viewcontrollers with my UINavigationController and when I'm on my 3rd UISubViewController I coded to 'popToRootViewController' and it pop's back, but the navigationbar-items push to the 2nd view controller not to the 1st..

  • I tried it with and without animating, but nothing is gonna change.
  • I tried to say self.navigationController.navigationBar pop back, but it do nothing on my bar.

Thanks for help..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断肠人 2024-10-07 08:16:19

我对你的问题有点困惑,但我认为这应该有帮助。据我所知,UINavigationController 上的“后退”按钮不能返回超过 1 次。所以你要做的就是添加另一个执行 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];
}

这应该覆盖弹出回控制器根目录(无论您在堆栈中)。您还必须对 .h 文件使用 IBAction 方法,但除此之外,它应该执行您想要执行的所有操作。

I am a little confused at your question but I think this should help. As far as I know you can't have the "back" button on a UINavigationController go back more than 1 pop. So what you do is you have to add another button that does the popToRootViewController function. Try something like this:

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

self.navigationItem.rightBarButtonItem = newButton;

This will add a button to the right on your navigation controller. The next step is to add a function called whatever you name in the action (in this case it needs to be called "homeAction"). This looks like so:

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

This should cover the pop back to the root of the controller where ever you are in the stack. You will also have to IBAction method to your .h file but other than that it should do everything you want to.

千紇 2024-10-07 08:16:19

除非你对 NavigationController 的 UIViewControllers 数组做了一些奇怪的事情,否则该方法应该是:

[self.navigationController popToRootViewControllerAnimated:YES];

unless you are doing something odd with the array of UIViewControllers of NavigationController, the method should be:

[self.navigationController popToRootViewControllerAnimated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文