问题描述
我有 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
的 viewControllers
属性:
You could use the UINavigationController
's viewControllers
property:
@property(nonatomic, copy) 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.
这篇关于如何识别导航堆栈中的前一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!