我想使用展开转场从当前 UIViewController
导航到第二个呈现的 UIViewController
:
let unwindDestinationViewController = self.presentingViewController!.presentingViewController!
switch unwindDestinationViewController{
case is UIViewControllerSubclass:
self.performSegue(withIdentifier: "unwindToUIViewControllerSubclass", sender: self)
break
default:
break
}
但是这不起作用。我还尝试将 case
语句更改为 UIViewControllerSubclass.Type
但它给了我一个错误:从 UIViewController 转换为不相关类型 UIViewControllerSubclass 总是失败。
如果有人能告诉我我做错了什么,我真的很感激。
最佳答案
您的代码对于检查类型是正确的:
case is UIViewControllerSubclass:
测试类的另一种方法:
case let vc as UIViewControllerSubclass:
如果您需要访问特定于该类的方法或属性,这会很有帮助。
如果您不需要使用 vc
则只需执行以下操作:
case _ as UIViewControllerSubclass:
<小时/>
您可以在此处使用 if
语句:
if unwindDestinationViewController is UIViewControllerSubclass {
self.performSegue(withIdentifier: "unwindToUIViewControllerSubclass", sender: self)
}
关于ios - 如何在 Swift 中检查实例的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44201819/