在 swift 中从导航控制器关闭后如何呈现另一个视图控制器? [英] How to present another view controller after dismiss from navigation controller in swift?
本文介绍了在 swift 中从导航控制器关闭后如何呈现另一个视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 swift 中从导航控制器关闭后呈现另一个视图控制器?
How to present another view controller after dismiss from navigation controller in swift ?
我正在使用导航控制器.
I am using Navigation controller.
ViewController1.swift
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
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)
})
}
关闭视图控制器后,它不会进入下一个视图控制器,即DataVC
After dismissing the View Controller, it will not goes to next viewcontroller i.e. DataVC
推荐答案
如果你想展示视图控制器,那么在你的dismissViewController中创建一个协议
If you want to present the view controller then create a protocol in your dismissViewController
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
这篇关于在 swift 中从导航控制器关闭后如何呈现另一个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文