0

In an iOS app, to move between screens, I can either present a new ViewController ("move forward") or dismiss a current ViewController ("move backward").

In my naive understanding, this is simply a way of moving back and forth in the stack of ViewControllers kept by the app.

I have an intuitive preference for dismissing a ViewController (where possible) rather than presenting a new ViewController. It gives me the feeling of operating within a finite set of ViewControllers which in turn makes me feel the app is memory efficient.

Say I am on View A and want to show View B, then presenting A would result in a stack A-B-A whereas dismissing B would keep the stack at A.

My question is this: is that justified? is there any (programmatic) downside to perpetually working by presenting new ViewController? Is it memory inefficient?

I wonder how many previous Views are being saved by the app and how long the stack could get, and if that is a reason to dismiss whenever possible.

AJGronevelt
  • 551
  • 1
  • 6
  • 22
  • 2
    If you want to show the same A - B after A, why would you ever present another A? Unless the second one (A) is different from the first one. In that case you should be presenting a new one. It is not about memory efficiency, it's more about view heirarchy that makes sense to the user. If you are moving forward, you should present/push. If you are moving backward you should dismiss/pop. It has nothing to do with whether the view controllers are the same or not. – Rakesha Shastri Dec 03 '18 at 09:17
  • You should need to go through [UINavigationController](https://developer.apple.com/documentation/uikit/uinavigationcontroller) in deep. – Mukesh Lokare Dec 03 '18 at 09:22

2 Answers2

0

I am not 100% sure if i understood you correctly, but it seems in-efficient memory wise and not sure how possible it is. You want to keep going backward basically, just dismissing views, right?

Meaning when you load B, then A, then you want to dimiss A to go to B again? Am i understanding this ok?

In that case views would have to be in a constant "stack" and i am sure it will make things go slower, but more imporatantly, from user perspective and user experience, something that they are not used to at all :/

emin
  • 289
  • 1
  • 10
-1

My understanding would be: If you want to show A again, then you should be going back to the instance of screen A that you already have. There might be special cases where it makes sense to have multiple instances of A (like detail screens for different objects), but even then: What you definitely should not do is build a never-ending stack of view controllers because as you already assumed: This will consume lots of unnecessary memory.

Maybe you should take a look at existing apps or the Apple Human Interface Guidelines and try to understand better how their view hierarchy works.

Robin Bork
  • 297
  • 2
  • 8