Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwind Segue in Xcode 6 Beta 4

I've been trying to add an unwind segue to a swift app in Xcode 6, and, in the release notes for the first three betas, it was declared to be unsupported. However, in Beta 4, that bug note is no longer present. I have heard that people have been able to get it to work, but I have had no such luck. So, my question is this: how should I try to see if the unwind segue will work in my app? What should I try? I am using a UIBarButtonItem to trigger the segue.

So far, I've put this code in the destination controller's .swift file:

@IBAction func unwindToSegue(segue:UIStoryboardSegue) {}

Using this code, I was able to connect the bar button to the function by control-dragging from the bar button to the exit icon, and then clicking the unwindToSegue method. That part has worked, but the code doesn't run, even when I put a breakpoint inside the function it wasn't called.

like image 418
trumpeter201 Avatar asked Jul 25 '14 17:07

trumpeter201


People also ask

How do you unwind segue in Xcode?

In your storyboard, create an unwind segue by right-clicking a triggering object and dragging to the Exit control at the top of your view controller's scene.


2 Answers

You need to put your unwindToSegue function in the originating ViewController (that is, the ViewController you are trying to return to).

Another thing you can try is to call the segue programmatically. First, wire an exit segue from the view controller icon to the exit icon (the three icons are all on the top of the view controller in Interface Builder). Give that segue a name such as "goBackHome". Then wire your button to call this @IBAction:

@IBAction func headHome() {
    println("Button seen.  Trigging exit segue manually...")
    self.performSegueWithIdentifier("goBackHome", sender: self)
}
like image 161
vacawama Avatar answered Oct 04 '22 00:10

vacawama


My problem was that I segue'd to a standard view controller(VC) from a custom container VC, but trying to segue back lost the original nav bar. Researching forums revealed that unwinding the segues would "pop" the new VC "protocols" off the stack & allow me to return to the original VC "protocols" unchanged.

I dragged in a button to the new VC, first dragged it to the swift file to create the action "back2main", modified it as below, THEN dragged the button to the exit icon at the top of the new VC itself, which generates the "unwind segue".

@IBAction func back2main(segue: UIStoryboardSegue) {
    dismissViewControllerAnimated(true, completion: nil)
}
like image 43
Rob Avatar answered Oct 04 '22 02:10

Rob