导航 Controllers/View 控制器使用堆栈

Navigation Controllers/View Controllers working with a stack

我正在尝试使用 Xcode 使用 Swift 编程语言创建一个 iPhone 游戏应用程序。我将项目创建为单视图应用程序,并且一直在添加视图控制器,并在需要时使用 Storyboard 将它们与 segues 连接起来。

经过数小时的研究(迟到总比不到好),据我了解,VCs 不使用堆栈,而导航控制器连接到其他 VCs 确实使用堆栈。因此,假设没有使用导航控制器,如果我使用 "show" segue 从一个 VC 到另一个,它不会将程序 VC 推到 VC启动了segue。它会显示 "modally".

关于这个我有几个问题。

  1. 当我在 VC 之间移动时,如果他们不使用堆栈,会发生什么情况?例如,当我从一个 VC 移动到另一个时,前一个 VC 是否从内存中删除,或者当我在两者之间移动时,内存是否继续接收越来越多的 VC 副本他们?

  2. 由于 VCs 在没有最初具有导航控制器的情况下无法从堆栈中弹出,有什么方法可以防止我的应用程序崩溃,例如在 [= 之间进行 segue 的特定方法40=]s?

  3. 在单视图 application/tabbed 应用程序等中创建项目时,这会影响应用程序无限期执行的操作,还是 Xcode 只是创建一个基本模板开始?例如,我可以从一个单视图应用程序开始,然后将它变成一个选项卡式应用程序吗?我假设答案是肯定的,但确认总是好的。

非常感谢有关这些问题的任何信息! 谢谢!

What is occurring when I am moving between the VCs, if they are not using a stack? For instance, when I move from one VC to another, is the previous VC removed from memory, or does the memory keep taking on more and more copies of VCs as I move between them?

前一个VC留在记忆中。每个新的 segue 都会创建一个新的 VC.

Since VCs cannot pop from a stack without initially having a navigation controller, is there any way to keep my app from crashing, such as a particular way to segue between VCs?

只有一种 segue 类型不会创建新的 VC,那就是 unwind segue。你用它来return到以前的VC。在 Stack Overflow 中搜索 "unwind segue" 以了解如何进行设置。

When a project is created in single-view application/tabbed application, etc., does this affect what the app will be capable of doing indefinitely, or does Xcode just create a basic template to start from? For instance, could I start off with a single-view application, but turn it into a tabbed-application? I assume the answer is yes, but confirmation is always nice.

模板只是让您从适合该模板类型的 Storyboard 和 ViewController 开始。您可以轻松删除或修改它们以更改您的应用程序的功能。