Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwind Segue in Xcode 6.1.1 with storyboard

Tags:

xcode

ios

xcode6

I have been reading that unwind segue's are bugged in Xcode 6. I am using Xcode 6.1.1 and I use swift.

I use the "Back" button that is put by the navigation controller. Thus I can't cntrl drag to the exit icon. Moreover I can't drag from viewController icon to exit icon either.

Is this a bug? Or else I am missing some fundamental knowledge about how to use unwind segue. How can I set unwind segues from the storyboard?

like image 565
Berkan Ercan Avatar asked Dec 04 '14 13:12

Berkan Ercan


2 Answers

I want to provide a detailed answer:

To perform an unwind segue, go to the view controller that you want to segue to and add the following function; (the name can change of course)

@IBAction func unwindToMainMenu(segue: UIStoryboardSegue) {

}

Once you add this function, you will be able to see this unwind function from any view controller on your storyboard. Just right click on the exit icon on the top of any view controller.exit icon right click

If you want to perform unwind with a button, then you can cntrl + drag from the button to exit icon and choose your unwindSegue function. Done!

Unwind with Button

If you want to perform unwind programmatically, then cntrl + drag from the viewController icon to the exit icon and choose the unwind function.

enter image description here

Afterwards, open the Document Outline and click on the unwind segue.

enter image description here

Go to Attributes Inspector inside Utilities and give an identifier to your unwind segue.

enter image description here

Lastly, call the performSegueWithIdentifier function like the following;

self.performSegueWithIdentifier("goToMainMenu", sender: self)

Hope that helps!

like image 176
Berkan Ercan Avatar answered Sep 28 '22 11:09

Berkan Ercan


Got it working. If you are presenting from a NavigationController or TabBarController(unsure about the TabBarController), you need to subclass the navigation controller and add the unwind segue to that. In storyboard don't forget to change the class of your navigation controller. My view hierarchy was NavController -> TableController -> DetailController. After adding method to custom NavBar class add it to the VC you want to RETURN to. You will then be able to ctrl-drag to exit. I consider this a bug, as once it is hooked up I was able to delete the subclass and return to stock NavigationController and it still worked.

like image 24
hidden-username Avatar answered Sep 28 '22 10:09

hidden-username