gpt4 book ai didi

ios - swift - 我如何检查特定的 viewController 是否是前一个 viewController

转载 作者:行者123 更新时间:2023-11-29 00:17:32 24 4
gpt4 key购买 nike

我正在尝试检测我以前的 viewController 是否是一个特定的,如果是,当我按回它时它将加载 tabBar Controller 。我正在使用 revealViewController 更改 View Controller 这是我的代码:在这里我保存了之前的 View Controller :

let newVC = 
self.storyboard?.instantiateViewController(withIdentifier:
storyboardIdentifiers.newViewControllerID) as! newViewController
newVC.previousVC = self
self.revealViewController().setFront(newVC, animated: true)

这是我的后退操作,我需要检查 previous 是否是第一个 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)
}

但是当我按回键时,它没有检测到它来自这些 View Controller 之一。

当我打印“self”时,它给了我这个结果

<MyPackege.firstViewController: 0x7f9e80f2b5a0>

但它不加载 TabBarController

最佳答案

不要使用 == 运算符,而是尝试使用 isKind(of: ) 方法来检查 View Controller 的类型

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)
}

关于ios - swift - 我如何检查特定的 viewController 是否是前一个 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44925724/

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