ios - 使用来自另一个操作的现有展开转场

标签 ios swift xcode button unwind-segue

我有两个按钮 - “Ok”和“Delete”,“Ok”将 segue 展开到最后一个 ViewController。

我希望“删除”按钮启动相同的展开转场,但要事先执行一些操作。 (在我的例子中,从 Firebase 中删除信息)。

如何将 Action 和展开转场结合起来?我尝试调用 PerformSegueWithIdentifier 函数,但没有成功。

最佳答案

通过 control 创建第二个 unwind segue - 从 Delete 按钮拖动到 Exit 图标。您甚至可以在目标 viewController 中使用现有的 @IBAction。给这个 segue 一个标识符(在 Document Outline View 中选择 segue 并在 Attributes Inspector 中设置标识符)例如 "deleteSegue" 和然后在 prepare(for:sender) 中检查标识符并从 Firebase 中删除信息。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "deleteSegue" {
        // delete data from Firebase
    }
}

跟进评论中的问题:

I want to perform an action BEFORE unwinding the segue - I want a popup to ask the user if he really wants to delete the item. only after that I want the item deleted and segue unwinded.

不是从 Delete 按钮连接 unwind segue,而是将它从 VC 顶部的 viewController 图标连接到 Exit图标。仍然给它标识符,然后在你想执行 segue 时调用 performSegue(withIdentifier: "deleteSegue", sender: self)

关于ios - 使用来自另一个操作的现有展开转场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48735982/

相关文章:

ios - 向项目添加自定义字体但是当我尝试使用它们时我得到一个 "fatal error: unexpectedly found nil while unwrapping an Optional value"

ios - 更改数字小数部分的字体

xcode - App Store 拒绝 - 准则 5.1.2 - 法律 - 隐私 - 数据使用和共享

iphone - 字符串到 NSDate 然后返回到字符串

ios - Swift AVAudioPlayer 不会播放用 AVAudioRecorder 录制的音频

swift - 我如何访问 Swift 的 REPL?

ios - 在类函数中使用异步调用/完成处理程序时,更新 Controller 中变量的最佳方法是什么?

ios - 不明白如何本地化iOS react native 应用程序的plist

ios - 如何快速录制带有特定阈值滤波器的音频

ios - 为 3D 模型的某些部分添加纹理