Berkan Ercan Berkan Ercan - 6 months ago 63
Swift Question

Perform push segue after an unwind segue

I am working on a camera app where the camera views are shown modally. After I am done with cropping. I perform an unwind segue to the

MainPageViewController
. (Please see the screenshot)

storyboard

My unwind function inside
MainPageViewController
is as follows;

@IBAction func unwindToMainMenu(segue: UIStoryboardSegue) {
self.performSegueWithIdentifier("Categories", sender: self)
}


where "categories" is the push segue identifier from
MainPageViewController
to
CategoriesTableViewController
.

The program enters the
unwindToMainMenu
function but it does not perform the push segue. Any idea how to fix this?

Note: I found the same question but the answer suggests to change the storyboard structure.

Answer

I want to provide my own solution to this problem for now. Any further answers are always welcome.

I put a boolean variable and viewDidAppear function to MainPageViewController.

var fromCamera = false

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

I set fromCamera to true before I perform unwind segue from CropViewController. By that way, I perform segue to category screen only if an unwind segue from crop view is performed.

Comments