gpt4 book ai didi

ios - 有没有办法找出 View Controller 是否从导航堆栈中弹出?

转载 作者:行者123 更新时间:2023-11-29 00:33:40 26 4
gpt4 key购买 nike

我正在尝试检测 View Controller 何时从导航堆栈中弹出,以某种方式引用堆栈的下一层上的 Controller (目前使用 Swift 3)。谢谢

最佳答案

UINavigationController 有一个属性 viewControllers,它包含当前在堆栈上的 View Controller 数组。您可以获得 View Controller 数组,然后从该数组中获取倒数第二个 View Controller :

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
}

关于ios - 有没有办法找出 View Controller 是否从导航堆栈中弹出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41145241/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com