0
votes

Basically I'm wondering what the proper way to present and release view controllers is.

My original understanding was that ViewControllerA presents ViewControllerB with -presentViewController: Animated: Completion:. Then ViewControllerB can release himself by calling -dismissViewControllerAnimated: Completion:.

Now, if I have three view controllers, A, B and C. A presents B, B presents C, and C returns to to A, how should I write this? I tried to call a dismiss from C on B, but that doesn't work. The only thing that actually seems to work is having C present A again, but is this proper?

Any help would be great, thanks!

1
by general rule of thumb creator should be responsible for destruction as well. - lead_the_zeppelin
"I tried to call a dismiss from C on B, but that doesn't work" It works if you do it correctly, so you need to think about why it "doesn't work" for you. Perhaps you should ask about that (and show your attempted code). - matt

1 Answers

3
votes

No, it is not proper to present A again. This will add a new instance, and as you go forward again to B and C, those will also be new instances. From C, you can either use an unwind segue to go back to A, or you can call dismissViewControllerAnimated:completion on self.presentingViewController.presentingViewController. If the first view controller in a series of presenting view controller does a dismissal, it cause all the presented controllers to be deallocated (assuming you aren't holding any other strong reference to them).