我正在尝试从Firebase检索滑动信息并将其发布到我的NotificationVC上,这与Instagram的通知供稿非常相似。我已经重新审视了一段时间,但似乎无法理解。
我的代码是
let DB_REF = Database.database().reference()
let USER_SWIPES_REF = DB_REF.child("UserSwipes")
var notifications = [Notifications]()
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return notifications.count
}
func fetchNotifications() {
guard let currentID = Auth.auth().currentUser?.uid else { return }
USER_SWIPES_REF.child(currentID).observe(.childAdded) { (snapshot) in
print(snapshot)
guard let dictionary = snapshot.value as? Dictionary<String, AnyObject> else { return }
guard let uid = dictionary["uid"] as? String else { return }
Database.fetchUser(with: uid, completion: { (user) in
if let fromId = dictionary["fromId"] as? String {
Database.fetchPoster(with: fromId, completion: { (post) in
let notification = Notifications(user: user, poster: post, dictionary: dictionary)
self.notifications.append(notification)
self.tableView.reloadData()
})
}
})
}
}
我不确定是什么问题,当我打印快照时,快照打印成功。但是当我在numberOfRowsInSection下返回notifications.count时,我只有一个空白页。我有一个简单的模板,因此如果要返回6,它将返回6个空白模板。目的是返回许多保存为空白模板的通知。如果有人可以帮助我,我将不胜感激!