【问题标题】:Navigation Controlled embedded in Container View custom segueNavigation Controlled 嵌入在 Container View 自定义 segue 中
【发布时间】:2019-03-11 18:23:18
【问题描述】:

我有UIContainerView,其中有UINavigationController 和其他嵌入在UINavigationController 中的VC(其中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 的呈现方式吗?

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

【问题讨论】:

    标签: ios swift uinavigationcontroller segue uicontainerview


    【解决方案1】:

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

    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  
    

    【讨论】:

    • 我所缺少的。非常感谢您的快速响应和良好的修复!
    猜你喜欢
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多