harlan kellaway's blog // iOS Quick Tip - Implementing Unwind Segues

Published 02-02-2015

Unwind segues are a great way to get from one view controller down the stack back up to another. However, implementing them is not so straight forward - I always forget myself, so I thought I'd share it here.

The key is to first add a method onto the view control to which you're segue-ing that takes in a UIStoryboardSegue. For example:

@interface ViewController
    - (IBAction)unwindFromMarketplaceView:(UIStoryboardSegue *)segue;
@end

Afterwards, head to Storyboard and ctrl+drag from the yellow Home icon on the top of the view your segueing from to its green Exit icon. This will create an unwind segue in Storyboard. Click that segue and give it an identifier.

To programmatically enact the segue - say when a button is touched, you can then call [self performSegueWithIdenfifier:(NSString)unwindSegueIdentifier sender:self] in the view controller that is being transitioned to.

Happy coding!





This blog is licensed under Attribution-Noncommercial-Share Alike 3.0 Unported license.