例如,使用 prepare(for segue:.. 我可以简单地传递 segue 值:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let nav = segue.destination as? UINavigationController, let manageCaptureVC = nav.topViewController as? ManageCaptureVC {
}
}
但现在我想在它被触发时有选择地取消它,而且似乎我只能使用 shouldPerformSegue
来做到这一点,因为在 prepare(for segue:.. 中使用 return 不会停止任何事情。
shouldPerformSegue 使用字符串而不是 UIStoryboardSegue
。我不确定这是为什么,我想要 UIStoryboardSegue
值。
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if debug_tutorialAllowCaptureBtnActions == false {
return false
}
//how do I get segue?
if let nav = segue.destination as? UINavigationController, let manageCaptureVC = nav.topViewController as? ManageCaptureVC {
}
return true
}
最佳答案
你需要
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "segueName" {
return
}
}
获取segue本身是没有意义的。您只需要知道 segue 标识符。此外,如果您需要做出此决定,请替换
if debug_tutorialAllowCaptureBtnActions == false {
return false
}
与
return tutorialAllowCaptureBtnActions
关于ios - 为什么 shouldPerformSegue 使用字符串,我该如何使用 UIStoryboardSegue 来代替它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53123869/