0

The Apple API docs indicate that segueForUnwindingToViewController() is deprecated and that I should use unwindForSegue() instead for use with a custom segue. I found this post but they still appear to use "segueForUnwindingToViewController()".

I'm not sure how to properly use the unwindForSegue() because segueForUnwindingToViewController() took the following arguments

  • toViewController
  • fromViewController
  • identifier

and returned a "UIStoryBoardSegue". E.g.

  override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue? {
    return MyCustomSegue(identifier: identifier!, source: fromViewController, destination: toViewController, performHandler: { () -> Void in } )
  }

How do I pass my identifier and create my custom segue instance using the new unwindForSegue()?

Community
  • 1
  • 1
Friedrich 'Fred' Clausen
  • 3,321
  • 8
  • 39
  • 70

1 Answers1

5

Well, this is not so hard as it could seems to be. I presume there are quite few ways to set up your custom segue.

Prerequisites:

  1. You need to create custom segue class for perform transition between UIViewControllers. Don't forget to set parent class - UIStoryboardSegue. (CustomSegue, for example)
  2. You need to override method in your container view controller -unwindForSegue:towardsViewController: where you can populate your segue from code

Important, you do not need to override this method in your custom view controllers that are not containers

One way, you can select you segue in storyboard and set it Class to your segue class(for example, CustomSegue)

Example where to set custom segue class

Another way, you can create segue from this method and simply perform it. For example,

- (void)unwindForSegue:(UIStoryboardSegue *)unwindSegue towardsViewController:(UIViewController *)subsequentVC {
        CustomSegue *segue = [[CustomSegue alloc] initWithIdentifier:<#Segue Identifier#> source:unwindSegue.sourceViewController destination:unwindSegue.destinationViewController];
        [segue perform];
}

Both method work properly. Hope this helps you.


P. S. You can try this test projects(Xcode 7.3) - https://github.com/igorkislyuk/custom-animation-unwind-segue
Igor Kislyuk
  • 330
  • 1
  • 4
  • 14