【发布时间】:2018-12-25 02:30:54
【问题描述】:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch section {
case 0:
var 语句的重新声明
one = Database.database().reference()
从数据库中收集信息
one.child("users").child("profile").observe(.value, with: {(snapshot) in
let num = snapshot.childrenCount
出错的地方
return Int(num)
})
default:
return 0
}
}
【问题讨论】:
-
一般来说,您不能从 Firebase 闭包返回值,因为它们不是函数,并且尝试直接从 Firebase(通过互联网)维护 tableView 会很慢。见下文 cmets。
-
您确定要读取/users/profile 中的所有 个节点吗?通常是 /users/uid/profile 来获取单个用户的数据。
标签: swift firebase firebase-realtime-database switch-statement