gpt4 book ai didi

ios - 我应该在我的 iOS (Swift) 应用程序生命周期中的哪个位置从 firebase 获取我的所有数据?

转载 作者:行者123 更新时间:2023-11-28 12:11:35 26 4
gpt4 key购买 nike

在从 firebase 获取所有数据之前,用户可能无法与我的应用交互。所以到目前为止我的新手计划是:

  1. 开始微调
  2. 从 firebase 获取数据(异步)
  3. 当第 2 步异步作业完成时,然后隐藏 spinner

作为新手,我的第一个想法通常不是可行的方法,必须有一种更聪明的方法,其中涉及框架(可能是应用程序生命周期中的某个位置)或最佳实践模式。
我在 www 上找不到任何有用的东西。链接也很有用。

最佳答案

您应该在 ViewDidLoad() 中获取数据

viewDidLoad()—Called when the view controller’s content view (the top of its view hierarchy) is created and loaded from a storyboard. The view controller’s outlets are guaranteed to have valid values by the time this method is called. Use this method to perform any additional setup required by your view controller.

通常,iOS 仅在其内容 View 首次创建时调用一次 viewDidLoad();但是,内容 View 不一定在 Controller 首次实例化时创建。相反,它是在系统或任何代码第一次访问 Controller 的 View 属性时延迟创建的。

当您在加载中查看时,您的数据将被提取。

如果您想在显示 View 时刷新数据,那么我可以使用。

viewWillAppear()—Called just before the view controller’s content view is added to the app’s view hierarchy. Use this method to trigger any operations that need to occur before the content view is presented onscreen. Despite the name, just because the system calls this method, it does not guarantee that the content view will become visible. The view may be obscured by other views or hidden. This method simply indicates that the content view is about to be added to the app’s view hierarchy.

关于ios - 我应该在我的 iOS (Swift) 应用程序生命周期中的哪个位置从 firebase 获取我的所有数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48337077/

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