![](/img/trans.png)
[英]Swift after dismiss Current ViewController then the Presenting ViewController not calling viewWillAppear()
[英]Swift dismiss current Viewcontroller after presenting new ViewController
我的場景,我正在嘗試創建多個present ViewController
。 在這里,在我需要關閉以前的 ViewController 之后呈現新的 ViewController。
ViewController A (RootViewController)
next button click to present ViewController C
ViewController B
然后View Controller B next button click to present ViewController C
。 現在,如果我關閉 ViewController C 需要顯示ViewController A
。
這是您可以繼續的方法,
class VCA: UIViewController {
@IBAction func onTapNextButton(_ sender: UIButton) {
if let controller = self.storyboard?.instantiateViewController(withIdentifier: "VCB") as? VCB {
self.present(controller, animated: true, completion: nil)
}
}
}
由於VCC
嵌入在UINavigationController
,因此您需要呈現UINavigationController
而不是VCC
。
對於這個子類UINavigationController
並將其設置為storyboard
的UINavigationController
class
。
class VCB: UIViewController {
@IBAction func onTapNextButton(_ sender: UIButton) {
if let controller = self.storyboard?.instantiateViewController(withIdentifier: "NavVC") {
self.dismiss(animated: false, completion: nil)
self.presentingViewController?.present(controller, animated: true, completion: nil)
}
}
}
class NavVC: UINavigationController {}
class VCC: UIViewController {
@IBAction func onTapCloseButton(_ sender: UIButton) {
self.navigationController?.dismiss(animated: true, completion: nil)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.