- 假设我有一个 View Controller (vcA),可以推送 QRCodeScannerViewcontroller (vcB)。当(vcB)扫描某些内容时,它会推送ResultviewController(vcC)。
-这 3 个 View 连接到 UInavigation Controller
-用户点击(vcC)上的后退按钮
我的问题是:
1) 如何在不更改 (vcB) 上的代码的情况下知道 (vcB) 是否可见? (vcB) 是一个 Pod
2)我将该代码放在哪里?我只能访问(vcA)
我尝试在(vcA)上添加此代码,但什么也没发生
override func viewDidDisappear(_ animated: Bool) {
if (vcB.isViewLoaded && (vcB.view.window != nil)){
print("vcb did appear!")
}
}
最佳答案
要知道导航堆栈中是否存在 cvB 类的实例,您可以使用这段代码:
let result = self.navigationController?.viewControllers.filter({
if let vcB = $0 as? UIViewController { // Replace UIViewController with your class, for example ViewControllerB
return true
}
return false
})
if result.isEmpty {
print("An instance of vcB's class hasn't been pused before")
} else {
print("An instance of vcB's class has been pused before")
}
关于swift - 如何检测推送的 View Controller 是否再次出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44801639/