[英]Swift 3 : How can I go to the previous ViewController and reload it?
[英]swift - how can i check if a specific viewController is the previous viewController
我正在嘗試檢測我以前的viewController是否是特定的,如果是當我按回時它將加載tabBar控制器。 我正在使用revealViewController更改視圖控制器,這是我的代碼:在這里,我保存了以前的視圖控制器:
let newVC =
self.storyboard?.instantiateViewController(withIdentifier:
storyboardIdentifiers.newViewControllerID) as! newViewController
newVC.previousVC = self
self.revealViewController().setFront(newVC, animated: true)
這是我的后動作,我需要檢查以前是否是第一個viewController
func backAction() {
let first = self.storyboard?.instantiateViewController(withIdentifier: storyboardIdentifiers.firstViewControllerID) as! firstViewController
let second = self.storyboard?.instantiateViewController(withIdentifier: storyboardIdentifiers.secondViewControllerID) as! secondViewController
if previousVC == first || previousVC == second {
previousVC = self.storyboard?.instantiateViewController(withIdentifier: storyboardIdentifiers.revealViewControllerID) as! SWRevealViewController
self.revealViewController().setFront(previousVC, animated: true)
}
else {
self.revealViewController().setFront(previousVC, animated: true)
}
但是當我按回它時,它不會檢測到它來自這些視圖控制器之一。
當我打印“自我”時,它給我這個結果
<MyPackege.firstViewController: 0x7f9e80f2b5a0>
但它不會加載TabBarController
而不是使用==
運算符,請嘗試使用isKind(of: )
方法來檢查viewcontroller的類型。
func backAction() {
let first = self.storyboard?.instantiateViewController(withIdentifier: storyboardIdentifiers.firstViewControllerID) as! firstViewController
let second = self.storyboard?.instantiateViewController(withIdentifier: storyboardIdentifiers.secondViewControllerID) as! secondViewController
if previousVC.isKind(of:firstViewController ) || previousVC.isKind(of:secondViewController ) {
previousVC = self.storyboard?.instantiateViewController(withIdentifier: storyboardIdentifiers.revealViewControllerID) as! SWRevealViewController
self.revealViewController().setFront(previousVC, animated: true)
}
else {
self.revealViewController().setFront(previousVC, animated: true)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.