-1

I am performing a segue to open another ViewController, afterwards I go back to the initial ViewController also via performSegue.

If I am doing this, all the values in the initial ViewController (e.g. the image in the UIImageView) are destroyed.

Do I need to save everything before I perform a Segue, or am I doing something completely wrong?

Thanks!

EDIT:

This is what I would like to achieve, if I press the menu button on my "HomeVC", the tableView of the SWRevealViewController pops out from the left side. If I press a cell, I get with segue push, to another UINavigationController. From this Controller I would like to go back to the "HomeVC".

Here is a screenshot.

enter image description here

Manuel
  • 613
  • 1
  • 6
  • 20

1 Answers1

3

You do it wrong. Performing a segue will create a brand new controller from the segue's destination and present/show it.

If you want to go back, you shouldn't perform another segue. Instead, you must dismiss() it if you presented the newController modally or pop() it if you show/push it.

This tutorial may help

Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278
  • Hello and thank you very much! I've already tried to dismiss the new ViewController, but I think the problem is, that I am using the SWRevealViewController. If I try to dismiss the newly opened ViewController nothing happens. This is how I would like to have my app performing: 1) opening the app, take a picture out of the gallery and set the image to the UIImageView (working so far) 2) open the menu (SWRevealViewController) and go to another VC (via segue at the moment) 3) close this VC and get back to the first VC (that's the problem) Have you got an idea? – Manuel Sep 15 '19 at 10:13
  • It doesn't matter. You must dismiss the top view to go back to previous. The important thing is how you performed segues. Modal -> dismiss, push/show -> pop – Mojtaba Hosseini Sep 15 '19 at 10:16
  • Sorry, the segue is of type push. So but if I try to use this: self.navigationController?.popViewController(animated: true), nothing happens. My segue goes to a UINavigationController and inside the rootViewController I try to perform the mentioned pop command. – Manuel Sep 15 '19 at 10:26
  • Consider to use Unwind Segue if you want to pass some data back to previous controller – Sergey Gamayunov Sep 15 '19 at 10:30