Unwind segue function with Back button

i0S Swift Issue

Question or problem in the Swift programming language:

I’m trying to call function when i’m pressing default Back button (e.g. < Settings) in Navigation Controller.

At other situations i’m creating custom button, after i’m Ctrl+Dragging to red Exit button in XCode and pointing it to Selection segue.

Now i need to use default back button of navigation controller, but i can’t set assign it to segue action because it’s no back button in Storyboard view (but it exists in Simulator).



I can create custom button in navigation contoller and assign it so custom unwind segue, but that button will be ugly without “< " symbol.

I’ve found some answers at stackoverflow, but they all are written in Objective-C :(.

How to solve the problem:

Solution 1:

You can use a delegate method to accomplish what you are doing.

Here is a really thought out swift tutorial that deal with delegates and segues:

What you are asking, ability to catch the back button’s action, isn’t possible the way you describe it.

Most people would recommend creating a custom button, then use an unwind segue.

There are lots of tutorials on custom back buttons just in case you’re new to swift, and the ugly part of the custom back button can be easily fixed by putting your own arrow there.

Also I found this previous asked question for future reference: Unwind segue from navigation back button in Swift

Solution 2:

Actually I just assigned the unwind segue to the entire view controller (right click from the yellow view controller outlet and drag to the exit outlet then select the function). And it works great so far. No need custom button, no delegate.
In fact, in my project the child is supposed to call the different parent’s function according to current caller view controller and simply using the same function name made my dreams come true.

This page helped me a lot: http://spin.atomicobject.com/2014/12/01/program-ios-unwind-segue/

Hope this helps!