0

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.

WizMeister
  • 609
  • 7
  • 16

1 Answers1

0
    @IBAction func button_Back(sender: AnyObject)
    {
     self.navigationController?.popViewControllerAnimated(true)
    }
Kirit Modi
  • 23,155
  • 15
  • 89
  • 112
  • Thanks but thing is I am doing this for multiple view controllers. Using popToViewController gives me a new instance. – WizMeister Dec 01 '14 at 12:09
  • 3
    Using popViewController does not, in itself, give you a new instance. Your controller's view may have unloaded, but you don't have a new instance unless you wrote your code wrong. – Daniel T. Dec 01 '14 at 12:52