Tobias
Tobias

Reputation: 578

Viewcontroller stack understanding issue

I got some serious problems understanding the viewcontroller stack. When will my app use a stack to save the previous viewcontrollers? Only if I use a navigation viewcontroller or anytime I use normal viewcontrollers and segue modally between them?

So I was just wondering if I use some sort of chained routine for example, like going from vc 1 to vc 2 and from vc 2 back to vc 1. No navigation controller, just modal segues, no unwinding. Does my app got performance issues because of a stack (which will grow everytime I go around) or doesn't it make any difference?

----updated

So basicly this is my problem. If I went through the routine of the app, the views get stacked everytime I do a transtition.

enter image description here

Upvotes: 0

Views: 102

Answers (1)

Jonah
Jonah

Reputation: 17958

UINavigationController will retain any controller you push onto it's navigation stack until you pop it back off.

Any UIViewController will retain a controller it presents modally until that child controller is dismissed.

In either case every controller will at a minimum consume some memory until you remove it. Apps which construct ever expanding stacks of controllers are likely to encounter a number of issues including:

  1. you will eventually run out of memory, how fast depends on how much memory each controller uses.
  2. you may see unexpected side effects if many controllers in the background react to the same event.
  3. users may become confused if they change state in an instance of controller 'A', push an instance of controller 'B' on top of it, and then "return" to a second instance of 'A' added to the top of the state. Since they're looking at a new controller and view whatever selection, scroll position, user input, or other state they set on the previous instance may be lost.
  4. developers, including you, may come to dread touching this app.

I suspect that everyone will have a better experience if you view controller management matches whatever visual metaphor you are presenting to the user.

Upvotes: 2

Related Questions