Gabe
Gabe

Reputation: 168

Dismissing and presenting View Controllers - An Explanation?

Recently, I've been reading about the concepts behind dismissing and presenting View Controller. I've been able to pick up on the ideas of dismissing the previous View Controller from the destination View Controller but I can't find an answer to a few questions that have been on my mind for quite a bit.

I'm mainly confused regarding the idea of when it is necessary to dismiss View Controllers and when it is not necessary to do so.

I'd appreciate it if anybody could help clear these questions up for me.

Upvotes: 2

Views: 110

Answers (4)

ClayJ
ClayJ

Reputation: 432

If there is a view controller which in most cases will be used only once (like login or settings etc.) — and especially if, after you’re done with it, it makes sense to return to the view controller you were on before — the best is to present it modally and dismiss it when you’re done. The rest of your view controllers stay in memory after the user can no longer see them, and this is expected behavior given the way Apple has created the methods for presenting and dismissing view controllers.

It is my understanding that in the Android world, this is not the case -- the default there is that when a new view controller is presented, the old one really does goes away.

Upvotes: 1

Jagdeep Singh
Jagdeep Singh

Reputation: 2626

As you know once user has signed in, log in screen not opens until user log out. So you should remove log in view controller from stack, it should not keep in memory. For this task, do not directly perform segue, you should change root view controller. There are lot of answers on stackoverflow for How to change root view controller?

Upvotes: 0

Aashish
Aashish

Reputation: 2696

Scenario 1: After performing a segue, it switches between your view controllers [ automatically dismisses the current ViewController and presents a new one ]. So, there's no reason to dismiss the login page.

Scenario 2: No you don't need to dismiss VC1.

Upvotes: 1

Tushar Sharma
Tushar Sharma

Reputation: 2882

1) When you go from login controller to second controller you just need to present the second controller and no need to dismiss first because if you are using navigation controller as a part of your segue all the view controllers are arranged in form of a stack . So second comes on top and first goes below it.Now if you need to got from second to first you can either dismiss your controller or pop your controller.When you dismiss a controller it is not popped from stack instead just moves behind and let the first controller come on top and when you pop a controller it removes itself from stack as well.

2) Same goes for your second question no need to dismiss first when you go from first to second controller.

Upvotes: 1

Related Questions