iosunwind-segue

Unwind to a viewController that is not in the current navigation view controller chain


I have the following scenes in the storyboard

VC1 => NavC => VC2 => VC3 => VC4 I programmatically segue from VC1 to either VC2 or VC3 based on a condition (I am doing that by instantiating NavC and change the viewControllers array). Now I would like to unwind from VC4 to VC1, but I think I am doing something wrong, because it is ignored and nothing is happening. To do this I have defined an IBAction called unwind1 in VC1, then I have created an exit segue from VC4 to its exit and called it segue1. I also have subclassed UINavigationController and have the following methods in it:

override func viewControllerForUnwindSegueAction(action: Selector, fromViewController: UIViewController, withSender sender: AnyObject!) -> UIViewController {
    return self.presentingViewController!
}

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

In method1 of VC4 I make a call to self.performSegueWithId("unwind1"). Although when I trace the execution control reaches to this line but it is ignored. When I put breakpoint in the two above-mentioned methods, execution control never gets there. Any thoughts on what I am doing wrong?


Solution

  • It seems that what I have done is the correct solution to the problem, because I just noticed it works on ios 8.1, but it does not work on ios 8.0. I assume it is a bug in the iOS!