我有两个按钮 - “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/