pop to view controller without instantiating a new one

728 views Asked by At

I am using a sidemenu for my app (Swift) and currently when I am taping on the menu I am creating a new instance of a ViewController.

I have a UICollectionView with some data loaded, then I go to another ViewController from the menu and then when I get back on the previous ViewController the UICollectionView is empty and I have to reload the data.

destViewController = mainStoryboard.instantiateViewControllerWithIdentifier("SettingsViewController") as UIViewController
self.setViewControllers([destViewController], animated: true)

I need to find a way to pop to the View Controller at it's previous state. Any hints? I have already used self.navigationController.popToViewController, same effect. I think the problem is that I am using instantiate method which create a new instance but I have no idea to check if there is already an instance and how to get back to it.

1

There are 1 answers

2
Kirit Modi On BEST ANSWER
    @IBAction func button_Back(sender: AnyObject)
    {
     self.navigationController?.popViewControllerAnimated(true)
    }