导航中上一个屏幕的导航控制器和标题?

发布于 2024-11-15 03:41:42 字数 600 浏览 2 评论 0原文

因此,如果我在一个屏幕上,我可以使用 PushViewController 导航到下一个导航屏幕,然后只需使用后退按钮即可到达下一个屏幕,并使用后退按钮返回上一个屏幕。

上一个屏幕(后退按钮将我们推到的屏幕)...它有名称吗? (就像以前的ViewController os之类的东西)?

这个问题背后的目标:

如果我有 5 个屏幕(分别为 1、2、3、4、5)...假设我从 1 -> 导航3,在另一种情况下,我从 2 -> 导航3. 我想说的是,如果“PreviousViewController 为 1”,则从 3 导航到 4 (1 -> 3 -> 4),否则如果 previousViewController 为 2,我想导航到 3 到 5 (2 - > 3 - > 5)...

我该如何完成这样的事情?

谢谢 !

ps 我知道我也可以用另一种方法尝试一些明智且合乎逻辑的方法,然后相应地推送ViewController。但如果有一个解决方案来检查 previousViewController,这将使我的任务变得简单,并且将是一次很好的学习体验。

So if I am on a screen I can navigate to the next navigation screen using the pushViewController and I simply get to the next screen, with a backButton to the previous screen.

Does the previous screen , (the screen which the back button pushes us to) ... does it have a name ? (Like previousViewController os something like that ) ??

My goal behind this question:

If I have 5 screens (1, 2, 3, 4, 5 respectively)... lets say I navigate from 1 -> 3, and in another case I navigate from 2 -> 3. I want to say that if the "PreviousViewController was 1" then navigate from 3 to 4 (1 -> 3 -> 4), else if the previousViewController was 2, I want to navigate to 3 to 5 (2 -> 3 -> 5)...

How do I accomplish something like that ?

Thanks !

p.s.
I know I could also try something sensible and logical with another approach and just pushViewController accordingly. But if there is a solution for checking the previousViewController, it would make my task easy and would be a great learning experience.

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

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

发布评论

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

评论(2

倾城花音 2024-11-22 03:41:42

实际上,您可以使用 UINavigationControllerviewControllers 属性来做到这一点。这就是 Apple 所说的它:

根视图控制器位于数组中的索引 0 处,后视图控制器位于索引 n-2 处,顶部控制器位于索引 n-1 处,其中 n 是数组中的项目数。

你的“前一个控制器”是Apple定义的“后视图控制器”,对应于索引n-2:

NSUInteger arraySize = [navController.viewControllers count];
UIViewController* prevController = [navController.viewControllers objectAtIndex:count-2];

You can actually do that by using the viewControllers property of UINavigationController. This is what Apple says about it:

The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.

Your "previous controller" is what Apple defines "back view controller", corresponding to index n-2:

NSUInteger arraySize = [navController.viewControllers count];
UIViewController* prevController = [navController.viewControllers objectAtIndex:count-2];
回忆追雨的时光 2024-11-22 03:41:42

不,没有 previousViewController。 UINavigationController 是作为堆栈实现的,因此您可以不断推送视图控制器,并且它们可以从堆栈中弹出。

仅供参考,如果您尝试查看所有视图控制器堆栈,则 UINavigationController 有名为“viewControllers”的属性,该属性以 NSArray 形式实现。

Nope, there is no previousViewController. UINavigationController is implemented as a stack so you keep pushing view controllers and those can pop themselves off the stack.

FYI, if you're trying to view all the stack of viewcontrollers then UINavigationController has property called "viewControllers" which is implemented as NSArray.

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