Please take a look at image I have shared. There are 4 ViewControllers in Main.storyboard:
Here is the viewController
list:
- AViewController
- BViewController
- CViewController
- DViewController
And AViewController is an initial ViewController.
AViewController has one button which is named 'Take Me To The BViewController'
BViewController has two buttons: 'Take Me To The CViewController' and Back Button
CViewController has two buttons: 'Take Me To The CViewController' and Back Button
DViewController has two buttons: 'Take Me To The AViewController' and Back Button
There are also 4 segues as you see:
- First segue is A to B
- Second segue is B to C
- Third segue is C to D
- Fourth segue is D to A
I wrote below code for these buttons:
self.performSegue(withIdentifier: "takeMeToTheBViewController", sender : self)
self.performSegue(withIdentifier: "takeMeToTheCViewController", sender : self)
self.performSegue(withIdentifier: "takeMeToTheDViewController", sender : self)
self.performSegue(withIdentifier: "takeMeToTheAViewController", sender : self)
And I wrote below code for the back button action:
self.dismiss(animated: true, completion: nil)
I have 3 questions:
First scenario: Let's assume I open the app. And then I click button in AViewController
. This action takes me to the BViewController. And then I click takeMeToTheCViewController
button in BViewController
. This action takes me to the CViewController
. And then I click takeMeToTheDViewController
button in CViewController
. This action takes me to the DViewController
. And then I click takeMeToTheAViewController
button in DViewController
. This action takes me to the AViewController
.
Here is the question 1:
Can you tell me instances in stack after all these actions? Are below items true for the stack?
- instance of
AViewController(1)
, - instance of
AViewController(2)
, - instance of
BViewController
, - instance of
CViewController
, - instance of
DViewController
Here is the question 1.1: Please reply this question according to first scenario above. If above instances items are true what should I do to remove below instances from the stack:
- instance of
AViewController(2)
, - instance of
BViewController
, - instance of
CViewController
, - instance of
DViewController
Because I don't need them now. I only need AViewController(1) because i am in AViewController currently.
Second scenario: Let's continue on first scenario. I was in first page. Now I click 'takeMeToTheBViewController' button in AViewController. Here is the question 2: Can you tell me instances in stack after all these actions? Are below items true for the stack?
- instance of
AViewController(1)
, - instance of
AViewController(2)
, - instance of
BViewController(1)
, - instance of
BViewController(2)
, - instance of
CViewController
, - instance of
DViewController
Third scenario: Let's continue on second scenario. I was in second page. Now I click 'back' button in BViewController(with dissmiss code as you know) This action takes me to the AViewController. Here is the question 3: Can you tell me instances in stack after all these actions? Are below items true for the stack?
- instance of
AViewController(1)
, - instance of
AViewController(2)
, - instance of
BViewController(1)
, - instance of
CViewController
, - instance of
DViewController
I mean instance of BViewController(2)
is removed from the stack by clicking back
button. Is this true?
Here is the question 4: Would it be a crash problem if these instances accumulate in the stack? Can you reply with question numbers please?