我有UIContainerView
,其中有UINavigationController
和其他VC嵌入UINavigationController
中(其中7个)。
在UINavigationController
内的这7个屏幕上,我正在调用一个弹出屏幕,然后该屏幕应重定向到其他屏幕,用户可以从该屏幕执行向后调用VC弹出窗口。
因此,UINavigationController
内部的用户旅程如下所示:
打开VC1(2,3,5,6,7)->调用弹出式VC->按下按钮->打开VC4->按下导航后退按钮->返回VC1。
这是我的代码:
@IBAction func didPressAuthors(_ sender: UIButton) {
self.dismiss(animated: true) {
if let navigation = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController {
let vc1 = self.storyboard!.instantiateViewController(withIdentifier: "FirstVC")
let vc2 = self.storyboard!.instantiateViewController(withIdentifier: "SecondVC")
let vc3 = self.storyboard!.instantiateViewController(withIdentifier: "ThirdVC")
let vc4 = self.storyboard!.instantiateViewController(withIdentifier: "FourthVC")
let vc5 = self.storyboard!.instantiateViewController(withIdentifier: "FifthVC")
let finalVC = self.storyboard!.instantiateViewController(withIdentifier: "Authors")
let userJourney = self.defaults.array(forKey: DefaultKeys.screenID.rawValue)
for vcName in userJourney! {
switch String(describing: vcName) {
case "FirstVC":
self.journeyVC.append(vc1)
case "SecondVC":
self.journeyVC.append(vc2)
case "ThirdVC":
self.journeyVC.append(vc3)
case "FourthVC":
self.journeyVC.append(vc4)
case "FifthVC":
self.journeyVC.append(vc5)
default:
self.journeyVC.append(finalVC)
}
}
self.journeyVC.append(finalVC)
navigation.setViewControllers(self.journeyVC, animated: true)
}
}
}
问题:
当我在UINavigationController
中没有UIContainerView
时,此代码可以正常工作,但是在我添加Container View
之后-它停止了。调用解除功能,但是什么也没发生。我缺少什么?我应该更改VC的显示方式吗?
如果有人可以帮助我解决此问题,将不胜感激。非常感谢,祝您周末愉快!
答案 0 :(得分:2)
您当前的根目录不在此处导航
if let navigation = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController {
这是通常的VC,导航是作为子级插入的,因此请尝试
if let root = UIApplication.shared.keyWindow?.rootViewController as? RootVC {
let nav = root.children![0] as! UINavigationController