如何识别导航堆栈中的先前视图控制器 [英] How to identify previous view controller in navigation stack

查看:132
本文介绍了如何识别导航堆栈中的先前视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个单独的 navigationcontrollers ,一个带有 RootViewController A,另一个带有 RootViewController B。

I have 2 seperate navigationcontrollers, one with RootViewController A and the other with RootViewController B.

我可以将 ViewController C推送到A或B的导航堆栈。

I am able to push ViewController C onto either A or B's navigation stack.

问题:当我在 ViewController C时,如何知道我是否在堆栈中属于A或B?

Question: When I am in ViewController C, how can I find out if I am in the stack belonging to A or B?

推荐答案

您可以使用 UINavigationController ' s viewControllers property:

You could use the UINavigationController's viewControllers property:


@property(nonatomic,复制)NSArray * viewControllers

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

Discussion: 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.

https ://developer.apple.com/documentation/uikit/uinavigationcontroller

您可以使用它来测试根视图控制器(数组索引处的控制器) 0)是视图控制器A或B.

You could use that to test whether the root view controller (the one at array index 0) is view controller A or B.

这篇关于如何识别导航堆栈中的先前视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆