0
votes

I have two buttons - "Ok" and "Delete", and the "Ok" unwinds the segue to the last ViewController.

I want the "Delete" button to fire up the same unwind segue, but to do some action beforehand. (In my case, delete info from Firebase).

How can I combine both an action and unwind segue ? I tried calling PerformSegueWithIdentifier function but it didn't work.

1

1 Answers

1
votes

Create a second unwind segue by control-dragging from your Delete button to the Exit icon. You can even use the existing @IBAction in your destination viewController. Give this segue an identifier (select the segue in the Document Outline view and set the identifier in the Attributes Inspector) such as "deleteSegue" and then in prepare(for:sender) check for the identifier and delete the info from Firebase.

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

Follow up question from the comments:

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.

Instead of wiring the unwind segue from the Delete button, wire it from the viewController icon at the top of the VC to the Exit icon. Still give it the identifier and then call performSegue(withIdentifier: "deleteSegue", sender: self) when you want to perform the segue.