导航中上一个屏幕的导航控制器和标题?
因此,如果我在一个屏幕上,我可以使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,您可以使用
UINavigationController
的viewControllers
属性来做到这一点。这就是 Apple 所说的它:你的“前一个控制器”是Apple定义的“后视图控制器”,对应于索引n-2:
You can actually do that by using the
viewControllers
property ofUINavigationController
. This is what Apple says about it:Your "previous controller" is what Apple defines "back view controller", corresponding to index n-2:
不,没有 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.