Search code examples
iosswiftuiviewcontrollerxcode7unwind-segue

Why do we use unwind segue if we can use segues to go back to any view controller?


I was wondering why we use unwind segues and make two pieces of code one in source view controller and one in destination view controller, and it's possible to just ctrl-drag from a button in -for example- view controller#3 to show view controller#1


Solution

  • Unwind segues give you a way to "unwind" the navigation stack back through push, modal, popover, and other types of segues. You use unwind segues to "go back" one or more steps in your navigation hierarchy. Unlike a normal segue, which create a new instance of their destination view controller and transitions to it, an unwind segue transitions to an existing view controller in your navigation hierarchy. Callbacks are provided to both the source and destination view controller before the transition begins. You can use these callbacks to pass data between the view controllers.

    When you create an unwind segue in Interface Builder you do not specify a destination view controller. The unwind segue determines which view controller in your navigation hierarchy to unwind to when it is triggered at runtime. This process is customizable and additional points of customization are provided for container view controllers to participate in the unwind process.

    Check : https://developer.apple.com/library/ios/technotes/tn2298/_index.html

     -(IBAction)unwindForSegue:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC{
    
    
       }