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数据
最佳答案
当您使用 Firestone 的 getData 函数时,就会发生这种情况。 使用快照监听器将消除此问题。
关于ios - 每次移动到不同 View Controller 时都会加载 Firestore 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54807100/