我想检查UIApplication.shared.windows
如果是,我想检查一个带有ID的ViewController是否在该NavigationController上。如果是,请将其置于堆栈顶部,如果没有创建viewController的实例并将其添加到导航堆栈中。
这就是我试图实现上述目标的方法,但我无法超越窗口打印。
有人可以建议我哪里出错吗?
func identifyAndPresentViewController(){
let windows = UIApplication.shared.windows
print("windows: \(windows)")
for window in windows{
print("window: \(window)")
if let nav = window.rootViewController as? UINavigationController {
print("nav: \(nav)")
let navId = nav.restorationIdentifier
print("navId: \(String(describing: navId))")
if navId == "VideoCallTVCNav" {
print("navId matches")
let vcs = nav.viewControllers
print("vcs: \(vcs)")
for vc in vcs{
print("vc: \(vc)")
if vc.restorationIdentifier == "VideoCallTVC"{
// Display VideoCallTVC inside nav with restorationId "VideoCallTVCNav"
print("VideoCallTVC exists")
}else{
// Create a instance of "VideoCallTVC" and display it inside nav with restorationId "VideoCallTVCNav"
print("VideoCallTVC does not exists")
}
}
}
}
}
}