在不同“层”之间跳转;在 UINavigationController 中

发布于 2024-12-29 17:00:17 字数 367 浏览 5 评论 0原文

我在导航控制器方面遇到了一个小问题。我设置了一个带有 2 个“分支”的导航控制器。 比如aviewController1>aViewController2>aviewController3,另一个分支是biewController1>bviewController2。现在我想做的是有一个选项可以从当前位置转到另一个分支的底部(第一个视图)(例如 aviewController3>bviewController1 等)。显然,一个简单的 [self.navigationController addSubview:someview.view] 不会完成这项工作,因为它只会让我到达该视图,并且仍然保留导航控制器的当前堆栈计数。我可以得到一些关于如何做到这一点的想法吗?

I've ran into a small problem with navigation controllers. I've set up a navigation controller with 2 'branches'.
Like aviewController1>aViewController2>aviewController3, and the other branch is biewController1>bviewController2. Now what I would like to do is to have an option to go from the current position to the bottom (first view) of the other branch (e.g aviewController3>bviewController1 etc). Obviously a simple [self.navigationController addSubview:someview.view]won't do the job as it will only get me to that view and will still retain the current stack count of the nav controller. Could I get some ideas on how to do this?

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

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

发布评论

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

评论(2

橘虞初梦 2025-01-05 17:00:17

只需多次调用 pop 即可弹出多个堆栈。如果您将所有 popViewController:animated: 调用设置为 NO,则应该是无缝的。

或者,导航控制器有一个 setViewControllers:animated: 方法,可以让您将整个堆栈交换为一组不同的视图控制器。使用它,您可以将现有的视图控制器堆栈复制到可变数组中,删除您不需要的视图控制器堆栈,追加您需要的视图控制器堆栈,然后一次性用新堆栈替换旧堆栈。

You can pop multiple stacks by just calling pop multiple times. If you make all the popViewController:animated: calls with animated set to NO, it should be seamless.

Alternatively, navigation controller has a setViewControllers:animated: method that lets you swap the whole stack out for a different set of view controllers. Using that you can copy the existing view controller stack into a mutable array, remove the ones you don't want, append the ones you do, and then replace the old stack with your new stack in one go.

孤单情人 2025-01-05 17:00:17

由于导航控制器基本上是一个堆栈,因此安全的方法是简单地弹出 a3、弹出 a2、弹出 a1,然后压入 b1。

如果分支是您的根控制器,那么您可以通过执行 popto 根控制器来加速它

Since the navigation controller is basically a stack, the safe way to do it is to simply pop a3, pop a2, pop a1 and then push b1.

if the branch is your root controller then you can speed it up by doing a popto Root controller

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