推动 VC,同时驳回前两个提出的 VC

问题描述 投票:0回答:1

我的导航控制器中有 VC1,我们从 VC1 中看到 VC2,然后从 VC2 中看到 VC3。当我点击VC3中的按钮时,我需要关闭VC2和VC3,然后将VC4推送到VC1

所以这个 VC1(模态呈现)-> VC2(模态呈现)-> VC3 对此 VC1(推送到导航控制器)-> VC4

我尝试了一切,但没有任何效果

swift uinavigationcontroller viewcontroller
1个回答
0
投票

第一种是当vc1 -> vc2时关闭vc2,从vc1进入vc3的方法。 第二种方法是按照您想要的方式进行的方法。 你想运行它吗?

extension UIViewController {
    
    func popAndPushViewController(goto: UIViewController) {
        if var vcArray = self.navigationController?.viewControllers {
            vcArray.removeLast()
            vcArray.append(goto)
            self.navigationController?.setViewControllers(vcArray, animated: true)
        }
    }


    func doublePopAndPushViewController(goto: UIViewController) {
        if var vcArray = self.navigationController?.viewControllers {
            vcArray.removeLast()
            vcArray.removeLast()
            vcArray.append(goto)
            self.navigationController?.setViewControllers(vcArray, animated: true)
        }
    }

}
let nextViewController = UIViewController()
self.doublePopAndPushViewController(goto: nextViewController)
© www.soinside.com 2019 - 2024. All rights reserved.