gpt4 book ai didi

ios - 每次移动到不同 View Controller 时都会加载 Firestore 数据

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

func loadUserThings() { 


Firestore.firestore().collection("users").document((Auth.auth().currentUser?.uid)!).getDocument { (snapshot, error) in
if let document = snapshot {
var data = document.data()
self.nameLabel.text = data?["username"] as? String ?? ""
self.usernameLabel.text = data?["username"] as? String ?? ""
}
}

}

上面的函数是在 View Controller 的viewdidLoad()中调用的。

我正在从 firebase firestore 检索数据。当我在 View Controller 之间移动或打开应用程序时,标签会再次加载。数据正在缓存,正如我在没有互联网时可以看到的那样,但即使如此,加载也需要时间。

每次在标签中加载Firestore数据

enter image description here

最佳答案

当您使用 Firestone 的 getData 函数时,就会发生这种情况。使用快照监听器将消除此问题。

关于ios - 每次移动到不同 View Controller 时都会加载 Firestore 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54807100/

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