如何在 UINavigationController 堆栈中使用 didReceiveMemoryWarning

发布于 2024-11-23 21:56:09 字数 885 浏览 1 评论 0原文

我的应用程序在堆栈中有多个 UIViewController(在 UINavigationController 下)。在某些情况下,当我位于内部 UIViewController 中时,我会收到内存警告(通常是在设备因后台运行的其他应用程序而过载时发生)。当这些内存警告发生时,应用程序会继续运行(大多数时候),然后当它返回到 rootViewController 时,它会重新加载它,但不会填充视图对象(主要是 UIButton 图像)。

我希望实现 didReceiveMemoryWarningapplicationDidReceiveMemoryWarning,但我不清楚如何做到这一点。

我正在寻找的最终结果是,当应用程序在内存警告后执行此“重新加载”时,它将以与用户开始“潜入”内部之前相同的状态“重新加载”rootViewController UIViewController。

  • 我应该如何实施?
  • 我应该在每个 UIViewController 中实现默认的 didReceiveMemoryWarning 吗?
  • 由于内存警告总是发生在内部 UIViewController 中,我应该如何让 rootViewController 知道它应该运行 didReceiveMemoryWarning
  • 我如何告诉 rootViewController 应该执行哪些设置?换句话说 - 我可以将设置保留在 didReceiveMemoryWarning 不会删除它们的地方,并在激活 didReceiveMemoryWarning 时“调用”它们,以便用户将看到与他们启动的屏幕相同的屏幕“级别导航”来自?

My app has several UIViewControllers in a stack (under a UINavigationController). In certain cases I get memory warnings when I'm in the inner UIViewControllers (mostly happens if the device is overloaded with other applications running in the background). When these memory warnings occur the application keeps on running (most of the times) and then when it gets back to the rootViewController it reloads it but doesn't fill in the view objects (mostly UIButton images).

I wish to implement didReceiveMemoryWarning and applicationDidReceiveMemoryWarning, but I'm not clear regarding to how to do that.

The end result I'm looking for is that when the application does this "reload" after memory warning it will "reload" rootViewController in the same status it was before the user started "diving" into the inner UIViewControllers.

  • How should I do the implementation?
  • Should I implement the default didReceiveMemoryWarning in each UIViewController?
  • Since the memory warning always occur in the inner UIViewControllers, how should I let the rootViewController know that it should run didReceiveMemoryWarning?
  • How do I tell the rootViewController which settings it should do? In other words - can I keep the settings someplace where didReceiveMemoryWarning doesn't delete them and upon activating didReceiveMemoryWarning "recall" them so the user will see the same screen they started the "levels navigation" from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘东忘西忘不掉你 2024-11-30 21:56:09

UINavigationController 堆栈上的任何不可见视图控制器都将转储其视图。它还会向您发送警告。如果视图控制器持有大型数据结构,则应尽可能转储它们。

根(另一个)控制器应该适当地处理 viewDidUnload 并能够循环通过另一个 loadView/viewDidLoad 阶段。

如果您希望状态相同,则需要保留所有这些信息。 NSUserDefaults 是执行此操作的标准位置。

Any non-visible view controller on the UINavigationController stack will dump its view. It will also send you the warning. If you have large data structures being held by the view controllers you should dump those if possible.

The root (an other) controllers should appropriately handle viewDidUnload and be able to cycle through another loadView/viewDidLoad phase.

If you want the state to be the same, you need to be persisting all that information. NSUserDefaults is a standard location to do that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文