我试图检测何时从导航堆栈中弹出一个视图控制器,这样我就可以在堆栈的下一层(当前使用Swift 3)上引用控制器。感谢
答案 0 :(得分:1)
UINavigationController
有一个属性viewControllers
,它包含当前堆栈中的视图控制器数组。您可以获取视图控制器数组,然后从该数组中获取倒数第二个视图控制器:
guard let navController = self.navigationController else {
print("We are not part of a navigation stack!")
return
}
let stack = navController.viewControllers
let stackCount = stackCount
if stackCount > 1 {
let nextVC = viewControllers[stackCount - 2]
//nextVC now contains the view controller one down from the current VC
} else {
//We are the root view controller
}