gpt4 book ai didi

ios - 如何从子 UIViewController 到父 UIViewController 并从那里到另一个子 UIViewController

转载 作者:行者123 更新时间:2023-11-28 11:35:06 25 4
gpt4 key购买 nike

我有一个父 UIViewController(MainVC)。从那里我有 2 个 segue 到 2 个 UIViewControllers:FirstVC(标识符:goFirstVC)和 SecondVC(标识符:goSecondVC )在 FirstVC 中,我有一个按钮 Save,当我点击它时,我想关闭 FirstVC 并继续 SecondVC.

这是我的代码:

 @IBAction func saveBtnTapped(_ sender: UIButton) {

//navigationController?.popViewController(animated: true)

let destinationController = self.storyboard?.instantiateViewController(withIdentifier: "goSecondVC") as! SecondVC
let presentingVC = self.presentingViewController
self.dismiss(animated: false, completion: { () -> Void in
presentingVC!.present(destinationController, animated: true, completion: nil)
})
}

这是我的问题的设计:

enter image description here

最佳答案

您可以使用setViewControllers 只保留父对象和SecondVC

let destinationController = self.storyboard?.instantiateViewController(withIdentifier: "goSecondVC") as! SecondVC

self.navigationController?.setViewControllers([self.navigationController!.viewControllers.first!,destinationController], animated: true)

关于ios - 如何从子 UIViewController 到父 UIViewController 并从那里到另一个子 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55609553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com