Search code examples
iosswiftprogrammatically-createdunwind-seguechildviewcontroller

Unwind segues with programmatically created view controllers


I have a view controller (PhotoViewController) which has a child view controller (CameraViewController). In CameraViewController, there is a button that sets off a chain of segueing through other programmatically created view controllers. On the last of these view controllers, I want to unwind to the original PhotoViewController. All examples I have found require you to have view controllers in the storyboard, which I don't have. How can I do this?


Solution

  • You have not understood what an unwind segue is. It is merely a way of reversing the calls that created the current view controller and got it into the view controller hierarchy, in the special case where you want to trigger this through a segue in a storyboard.

    • For example, if you (or the storyboard) called pushViewController (for a pushed view controller), an unwind segue is just a way of calling popViewController.

    • Or, if you called (or the storyboard) called present (for a modally presented view controller), an unwind segue is just a way of calling dismiss.

    If you don't have your view controllers in a storyboard, you don't need an unwind segue; you just do one of those two things, directly, in code.

    Remember, we all got along for years just fine without unwind segues. In fact, we all got along for years without storyboards! And so can you.