ios - 在 iOS 中避免/禁用状态保存
问题描述
我正在开发一个具有以下界面(假设)的小型应用程序
启动屏幕->屏幕X->屏幕Y
问题是,当我关闭应用程序并同时再次打开它时,它再次显示最后一次看到的屏幕,然后显示启动屏幕,然后显示初始视图控制器。
我也检查了其他一些应用程序,但它们的行为并非如此,例如谷歌地图。
我还在 AppDelegate 中实现了以下两种方法,如下所示
func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
return false
}
func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
return false
}
但没有任何工作。有人可以建议我该怎么做
谢谢。
解决方案
不确定这是否有帮助,但你可以像我一样做并利用NotificationCenter
// In something like viewDidLoad
NotificationCenter.default.addObserver(self, selector: #selector(returnedFromBackground), name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil)
...
@objc func returnedFromBackground() {
// Anything you want to preserve/save/do and then segue (or whatever you use) to your launching screen
}
推荐阅读
- java - Spring Data Elasticsearch 不会隐式地从注解创建映射
- python - 从 tsv 文件中获取和合并数据
- google-apps-script - 希望在谷歌表格中有一个按钮,添加另一个相同的部分
- python - 如何使用 PyPDF2 复制和更改 PDF 文件的名称
- python - 卡特彼勒项目混乱
- javascript - 如何使用 vuex 访问数组对象?
- android - 如何在用户滚动之前准备像tiktok这样的高级视频?,颤动android ios
- ssh - Vagrant 设置 ssh 主机名以匹配私有 IP 失败
- r - 如何在 R 中绘制带有圆形列而不是常规条形的条形图?
- javascript - 反应切换开关显示/隐藏视图