gpt4 book ai didi

ios - 在 swift 4 中显示和关闭 View Controller

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

我正在尝试呈现一个 View Controller 并关闭我当前的模态视图。我在 StackOverflow 上看到了答案,但我不明白。

self.dismissViewControllerAnimated(true, completion: {
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("myViewController")
self.presentViewController(vc!, animated: true, completion: nil)
})

谁能告诉我,如何简单地做到这一点?谢谢

最佳答案

检查堆栈中的主 Controller 并弹出所有其他 View Controller ,然后呈现新的 View Controller 。

if let controllers =  self.navigationController?.viewControllers  {
for vc in controllers {
// Check if the view controller is of MainViewController type
if let myVC = vc as? MainViewController {
self.navigationController?.popToViewController(myVC, animated: false)
}
}
}

推送 View Controller :

let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "secondVC") as! SecondViewController
self.navigationController?.pushViewController(secondVC, animated: true)

或当前 View Controller :

let next = self.storyboard?.instantiateViewController(withIdentifier: "secondVC") as! SecondViewController
self.present(next as UIViewController, animated: true, completion: nil)

关于ios - 在 swift 4 中显示和关闭 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49194130/

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