Problem
My problem is that unwind process is not triggered even though back button is clicked.
My code
I have a class 1stViewController that uses a custom segue to 2ndViewController. The custom segue is the following:
override func perform() {
let sourceVC = self.source as! 1stViewController
let destinationVC = self.destination as! 2ndViewController
sourceVC.addChildViewController(destinationVC)
sourceVC.view.addSubview(destinationVC.view)
}
In my 2ndViewController I have added a button that triggers an unwinding segue back to 1stViewController. The unwinding segue is connected through the identifier of the unwind segue triggering exit in the 2ndViewController. Thus, I have created an IBAction that the unwind segue exit is connected to:
@IBAction func unwindToFeed(segue: UIStoryboardSegue) {}
I have set the identifier of the unwind segue equal to the one used in the action function of the button
func handleActionBackButton(){
print("here")
self.performSegue(withIdentifier: "unwindId", sender: self)
}
"Here" is printed when button is clicked, but it seems like performSegue is not.
I guessed that I needed a custom unwindSegue class as well, so I created unwindSegueEventToFeed:
class unwindSegueEventToFeed: UIStoryboardSegue {
override func perform() {
let sourceVC = self.source as! 2ndViewController
let destinationVC = self.destination as! 1stViewController
let sourceView = sourceVC.view as UIView!
let destView = destinationVC.view as UIView!
let window = UIApplication.shared.keyWindow
window?.insertSubview(destView!, aboveSubview: sourceView!)
sourceVC.dismiss(animated: false, completion: nil)
}
} ...which is called in the 2ndViewController:
override func segueForUnwinding(to toViewController: UIViewController, from fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue? {
return unwindSegueEventToFeed(identifier: identifier, source: fromViewController, destination: toViewController)
}
Any clues on what I have to do different to trigger the unwinding process?