Perform UnwindSegue correctly

56 views Asked by At

I am trying to create an Unwind segue that brings from the DetailViewcontroller to the SecondViewcontroller.

I have created an IBAction like this one that can be intercepted by Segues :

@IBAction func segueToSecondVC(sender: UIStoryboardSegue) {
    print("segue intercepted by IBAction segueToSecondVC")
}

An placed it in the receiver ViewController (secondViewController).

Then I moved to the Detailviewcontroller and clicked to the third figure on the top of the viewcontroller (exit),clicked to the segueToSecondVC IBAction that appeared in the list of events and dragged it into the button "TURN BACK"(placed in the Detailviewcontroller) in order to associate the button to the event. In this way the button should be connected with the event and should turn back to the secondVC with an automatic Hidden Segue.

But it doesn't work, the simulator crash and I am redirected to xCode editor with an error in the Appdelegate that says "Thread 1: signal SIGABRT" I don't know why it doesn't work, anyone could help me?

1

There are 1 answers

1
swift2geek On

you can use Unwind like this:

 @IBAction func prepareForUnwind(segue: UIStoryboardSegue){}


@IBAction func closePressed(_ sender: Any) {
        performSegue(withIdentifier: "unwindToAnotherVC", sender: nil)
    }

good rule, is to add all your segues names to constants file: Create swift file

import Foundation

// Segues
let TO_LOGIN = "toLogin"
let TO_CREATE_ACCOUNT = "toCreateAccount"
let UNWIND = "unwindToChannel"

and then use UNWIND in

@IBAction func closePressed(_ sender: Any) {
            performSegue(withIdentifier: UNWIND, sender: nil)
        }