Search code examples
iosswiftios9uistoryboarduistoryboardsegue

How unwindForSegue:towardsViewController: works?


In my simple app, I have created some controllers with basic segues between them:

Yellow controller -> BlueController -> GreenController -> OrangeController. Every of them has its own custom class.

From OrangeController I created unwindSegue to my YellowController. It is ok.

Within every class I put:

override func unwindForSegue(unwindSegue: UIStoryboardSegue, towardsViewController subsequentVC: UIViewController) {
    print(unwindSegue)
    print(subsequentVC)
}

But it was not called at all. Why? What demo should I prepare to test this functionality?

The same is with:

func allowedChildViewControllersForUnwindingFromSource(source: UIStoryboardUnwindSegueSource) -> [UIViewController]
func childViewControllerContainingSegueSource(source: UIStoryboardUnwindSegueSource) -> UIViewController?

Solution

  • Implement the method with IBAction returnType

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

    In Storyboard, link the control (which is responsible for the back action) to the exit action in the viewcontroller. enter image description here

    enter image description here