导航控制嵌入在容器视图自定义 segue 中

Navigation Controlled embedded in Container View custom segue

我有 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)
        }
    }
}

问题:

当我在 UIContainerView 中没有 UINavigationController 时,此代码工作正常,但在我添加 Container View 之后 - 它停止了。调用了 Dismiss func,但没有任何反应。我缺少什么?我应该更改 VC 的显示方式吗?

如果有人能帮我解决这个问题,我将不胜感激。非常感谢,周末愉快!

您当前的根不是这里的导航

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