简体   繁体   English

iOS Swift 4:关闭或显示ViewController效率更高

[英]iOS Swift 4: ist it more efficient to dismiss or present a ViewController

In an iOS app, to move between screens, I can either present a new ViewController ("move forward") or dismiss a current ViewController ("move backward"). 在iOS应用中,要在屏幕之间移动,我可以显示一个新的ViewController(“向前移动”)或关闭当前的ViewController(“向后移动”)。

In my naive understanding, this is simply a way of moving back and forth in the stack of ViewControllers kept by the app. 以我幼稚的理解,这只是在应用程序保存的ViewController堆栈中来回移动的一种方式。

I have an intuitive preference for dismissing a ViewController (where possible) rather than presenting a new ViewController. 我有一个直观的偏好,就是解雇一个ViewController(如果可能的话),而不是展示一个新的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. 它给我一种在有限的ViewControllers中操作的感觉,这反过来又让我感到该应用程序具有内存效率。

Say I am on View A and want to show View B, then presenting A would result in a stack ABA whereas dismissing B would keep the stack at A. 假设我在视图A上并想显示视图B,然后显示A将导致堆栈ABA,而关闭B将使堆栈保持在A。

My question is this: is that justified? 我的问题是:这合理吗? is there any (programmatic) downside to perpetually working by presenting new ViewController? 提供新的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. 我想知道应用程序正在保存多少个以前的视图,堆栈可以保存多长时间,这是否是一个尽可能取消的原因。

I am not 100% sure if i understood you correctly, but it seems in-efficient memory wise and not sure how possible it is. 我不确定我是否正确地理解了您,但不是100%肯定,但似乎内存使用效率低下,不确定该怎么做。 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? 意思是当您先加载B,然后加载A,然后又想放弃A再转到B? 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 :/ 在那种情况下,视图必须处于恒定的“堆栈”中,并且我确信它将使事情变慢,但更重要的是,从用户的角度和用户体验来看,它们是一点都不习惯的:/

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. 我的理解是:如果您想再次显示A,那么您应该回到已经拥有的屏幕A的实例。 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. 在某些特殊情况下,拥有多个A实例是很有意义的(例如针对不同对象的详细信息屏幕),但是即使如此:您绝对不应该建立一个永无休止的视图控制器堆栈,因为您已经假设:这将消耗大量不必要的内存。

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. 也许您应该看看现有的应用程序或《 Apple人机界面指南》,并尝试更好地了解它们的视图层次结构如何工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM