ios - 在呈现呈现的 viewController 之后呈现 viewController 会发生什么?

标签 ios uiviewcontroller presentviewcontroller

在呈现呈现的 viewController 之后呈现 viewController 会发生什么。它的实例是否继续存在?当它被呈现的 viewController View 遮挡时,它是否被销毁?如果它被破坏了,我如何告诉系统不要破坏它,而是保持它完好无损?

我正在设计一款游戏,当点击某个按钮时,游戏会被显示的 viewController 遮挡。当玩家返回游戏时,我希望它恢复到呈现 viewController 之前的状态

最佳答案

呈现的 View Controller 保留它的实例,并且在呈现的 View Controller 被关闭后将控制返回给它。事实上,你应该有呈现 View Controller dismiss the presented controller如果可能的话。

由于 UIViewControllers 的实例在呈现(或推送)另一个 View Controller 时保持不变,因此最佳实践是实现 didReceiveMemoryWarning方法在你的 UIViewControllers 中释放你可以释放的任何内存(清除缓存等)。您清除的任何数据都可能需要在 viewWillAppear 方法中重新填充。

来自 View Controller Programming Guide for iOS 的其他信息:

Support for presenting view controllers is built in to the UIViewController class and is available to all view controller objects. You can present any view controller from any other view controller, although UIKit might reroute the request to a different view controller. Presenting a view controller creates a relationship between the original view controller, known as the presenting view controller, and the new view controller to be displayed, known as the presented view controller. This relationship forms part of the view controller hierarchy and remains in place until the presented view controller is dismissed.

关于ios - 在呈现呈现的 viewController 之后呈现 viewController 会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31626934/

相关文章:

ios - 如何在ios中点击手机附件时获取数据

ios - 如何让我的视频背景继续使用 swift 播放?

ios - 警告 : Attempt to present * on * whose view is not in the window hierarchy - swift

ios - 使用一个动画关闭和呈现模态视图 Controller

swift - 推送到导航 Controller 不起作用

ios - 为什么 UIView 周围有边框?

ios - 将进度 View 添加到搜索栏

ios - Mapbox 清除路线折线

ios - 想从 appdelegate 调用 ViewController 的方法

ios - 如何在没有 Storyboard的情况下推送新 View Swift