Perfom show segue inside an unwind segue

137 Views Asked by At

I have seen a few questions asking this question, but the answers do not seem conclusive. Using XCode 7 with iOS 9, I want to unwind to a main menu view controller from an arbitrary number of child view controllers. I expected something like the following to do what I need:

@IBAction func returnToMenuScreen(segue: UIStoryboardSegue) {
    let departureController = segue.sourceViewController
    if departureController.title == "ChildViewController" {
        print("ChildViewController")
        self.performSegueWithIdentifier("NewSegue", sender: departureController)
    }
}

The print function is called, but the performSegueWithIdentifier is not. Similar questions seem to point to a timing issue, but I am having no luck.

To summarize, how can navigate between children view controllers of a parent view controller? I want to unwind to parent then segue to an arbitrary child view controller. Any and all help is appreciated!

1

There are 1 best solutions below

3
Mudith Chathuranga Silva On

I tried to understand you question, But your data is not adequate to find a solution to your problem. May be you didn't wire up correctly unwind function. S o it's better to follow some tutorials about unwind segues. Here is the link of apple, which describe about unwind segue. Go to bottom of this given link. Then you can find out how to unwind segue correctly. hope that this link will help to find your problem.

https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson8.html

**** update****

Try this solution :-

@IBAction func unwindToMainMenu(segue: UIStoryboardSegue) {
dispatch_after(1, dispatch_get_main_queue()) { () -> Void in
    self.performSegueWithIdentifier("viewController", sender: self)
 }
}

or you can introduce a variable to handle segue in viewWillAppear.

PUT

var show = false // IN UNWIND VIEW CONTROLLER 

change the fromCamera = true, in prepareForSegue

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showDetails" {
        let MainViewController = segue.destinationViewController as? JobInformationViewController
        MainViewController!.show= true
    }
}

AND use like this

 override func viewDidAppear(animated: Bool) {
   if show {
      self.performSegueWithIdentifier("categorySelection", sender: self)
      self.show= false
   }
 }