ios - 为什么 shouldPerformSegue 使用字符串,我该如何使用 UIStoryboardSegue 来代替它?

标签 ios swift segue uistoryboardsegue

例如,使用 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/

相关文章:

objective-c - 是否可以在静态库中使用 FlurryAPI?

ios - 将之前计算的数据添加到每次按下 UIButton 时生成的新数据中

ios - 奥林巴斯相机套件 : How to avoid the rotation of live view?

swift - 为什么 Storyboard弹出框出现在导航 Controller 内的后续 View 上

swift - 访问 tableView SWIFT 中的文本字段

ios - 检查 TextField 不为空后如何启用 UIBarItem

ios - 使用 AFNetworking Multipart 表单数据上传多个图像不起作用

ios - assetExport完成后检索路径

swift - promise 套件 6 : Cannot invoke 'then' with an argument list of type '((String, String) -> Promise<Data>)'

ios - 关于 segue 到 viewcontroller 的问题