在呈现呈现的 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/