例如,使用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
}
答案 0 :(得分:2)
您需要
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
if identifier == "segueName" {
return
}
}
获取segue本身是没有意义的。您只需要知道segue标识符。另外,如果您需要做出决定,请替换
if debug_tutorialAllowCaptureBtnActions == false {
return false
}
与
return tutorialAllowCaptureBtnActions