gpt4 book ai didi

ios - swift 从导航 Controller 中解雇后如何呈现另一个 View Controller ?

转载 作者:搜寻专家 更新时间:2023-11-01 07:03:31 26 4
gpt4 key购买 nike

如何在 swift 从导航 Controller 中解雇后呈现另一个 View Controller ?

我正在使用导航 Controller 。

ViewController1.swift

func pushTo(viewController: UIViewController) {
let showLocalPwd = self.storyboard?.instantiateViewController(withIdentifier: "LocalPwdVC") as! LocalPwdVC
self.navigationController?.present(showLocalPwd, animated: true, completion: nil)
}

ViewController2.swift

    @IBAction func btnVerify(_ sender: Any)
{
self.dismiss(animated: true, completion: {
let vc = self.storyboard.instantiateViewController(withIdentifier: "DataVC") as! DataVC
self.navigationController.pushViewController(vc, animated: true)
})
}

关闭 View Controller 后,它不会转到下一个 View Controller ,即 DataVC

最佳答案

如果你想呈现 View Controller ,那么在你的 dismissViewController 中创建一个协议(protocol)

protocol dismissViewController {
func presentCompletedViewController()
}
// Then create a delegate
var delegate = dismissViewController? = nil
// If you are using action to dismiss your ViewController then call delegate

@IBAction func YourButton(_ sender: Any) {
self.dismiss(animated: true) {
self.delegate!.presentCompletedViewController()
}
}

//And then call this in your main or homeViewController
class HomeViewController: UIViewController, dismissViewController {
func presentCompletedViewController(){
// enter code to present view controller
}
// And at last don't forget to call delegate
yourVc.delegate = self
you need to call this delegate in which you are presenting your dismissViewController

关于ios - swift 从导航 Controller 中解雇后如何呈现另一个 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49613480/

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