Swift back button segue

Viewed 5164

I have a navigation tableview controller Calculator and that goes to AddActiveIngredients which is where I add everything in for the calculator.

I have the segue method backButton in Calculator and in AddActiveIngredients I have click dragged the segue from the controller to exit and selected the segue in the Calculator class.

enter image description here

The segue identifier is also backButton but it's not doing anything.

I've tried this code to try and trigger the segue manually but that's not working. Am I missing something so simple?

override func didMoveToParentViewController(parent: UIViewController?) {
    if (!(parent?.isEqual(self.parentViewController) ?? false)) {
        print("Back Button Pressed!")

        self.performSegueWithIdentifier("backButton", sender: self)
    }
}
3 Answers

with Swift 5 you can use Dismiss function

@IBAction func dismissViewController(_ sender: Any) {
        //Go back to previous controller
        dismiss(animated: true, completion: nil)
    }
Related