gpt4 book ai didi

iOS 应用程序在保留在后台时返回到 rootViewController

转载 作者:行者123 更新时间:2023-11-29 00:00:35 25 4
gpt4 key购买 nike

我的 iOS 应用程序在后台保持较长时间后会返回到 rootViewController。为了证明我有下面的图片 enter image description here

我一直导航到 ViewControllerC 并将应用程序保持在后台,当我返回应用程序时说 30 分钟后,应用程序显示 rootViewController,即 ViewControllerA。

我希望它保留在 ViewControllerC 上,就像它保留在 Whatsapp 中一样。我知道当系统内存不足时,我的应用程序(空闲应用程序)将从内存中删除,因此当我打开应用程序时,它将带我回到指定的初始 View Controller 。但是为什么 whatsapp 不会发生这种情况呢?

最佳答案

Apple 为这种情况提供了解决方案:UIViewController 和 App Delegate 具有允许您保存和恢复状态的方法。当应用程序进入后台时,当前配置( View Controller 的 View 显示的内容)将被保存。这样,即使应用程序退出,当它重新启动时,它也可以在向用户显示之前返回到该配置。因此,从后台返回并退出看起来就像从单纯的后台返回一样。

有关完整详细信息,请参阅 Apple 的文档。这是一个很好的起点:

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/PreservingandRestoringState.html

关于iOS 应用程序在保留在后台时返回到 rootViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49584684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com