我试图在从 firebase 查询数据时显示微调器,并在返回查询结果时隐藏它。 有什么方法可以知道查询是否已完成检索所有数据? ?
self.handle = self.ref.child("users").observeEventType(.Value, withBlock: { (snapshot) in
if snapshot.exists() {
print ("snapshot exist")
print (snapshot.childrenCount)
}
else {
print ("snapshot doesn't exist")
}
})
最佳答案
当调用 .Value
观察者的回调 block 时,它会获取该位置当前已知的所有数据。因此您可以将微调器隐藏在 block 中:
self.handle = self.ref.child("users").observeEventType(.Value, withBlock: { (snapshot) in
// TODO: hide spinner here
if snapshot.exists() {
print ("snapshot exist")
print (snapshot.childrenCount)
}
else {
print ("snapshot doesn't exist")
}
})
请记住,Firebase 观察者会不断同步数据,因此您的阻止可能会运行多次。
关于swift - Firebase:如何检查查询是否完成? ( swift ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38493291/