0

From an initial ViewController I've modally presented a second ViewController using a ShowDetail segue in the storyboard and a performSegueWithIdentifier: method call. The problem is when I dismiss this modal ViewController with the method dismissViewControllerAnimated: the initial ViewController is reinstantiated calling the viewDidLoad again.

I've tried using a Push segue instead of the Show Detail and the initial ViewController keeps allocated in the background as it should.

What might be going on? The initial ViewController never even calls the memory warning method.

Lucas Pereira
  • 477
  • 1
  • 11
  • 23

1 Answers1

0

Have you tried unwindSegues?

***** Long explanation ahead, skip to solution if you want the quick way *****

First of all, if it is a ShowDetail, it is not a modal view. Do try to see which is your case. Modal segues can carry information backwards, but are a bit more complicated than push ones. If you are modally presenting it, you should use Present Modally instead of a ShowDetail.

A modal presentation will always take the top view position in the stack, and Show Detail does as well, depending in how your views are set. For instance, if you have a detail view in stack, IT will be replaced rather than the stack top view.

Try choosing up to a specific segue, I particularly recommend modal assuming you need more than simple pushes (Or the Show would have closed the problem, being the equivalent to the previous deprecated push. If you only need something simple, Show is the way)

Now we've cleared this, what probably is happening is that the view is being removes since Show Detail replaces views instead of pushing them, and it has to perform init again.

***** Solution: *****

The solution then should be not to lose the view when replacing, and reinitializing it, what dismissViewControllerAnimated: does. If you use unwind segues, though, the view should be replaced BUT retained by ARC.

The following link has the best explanation all over the net about how to use it:

What are Unwind segues for and how do you use them?

Community
  • 1
  • 1
Elindor
  • 175
  • 2
  • 8
  • I've actually done some testing and I've figured that If I remove the Initial VC from the Tabbarcontroller it works as it should. However, even presenting the second vc from the tabbarcontroller the initial VC is still reinstantiated after dismissviewcontroller: – Lucas Pereira Oct 06 '15 at 14:49