gpt4 book ai didi

ios - 无法在 TableViewController 中显示来自 Firebase 数据库的项目

转载 作者:行者123 更新时间:2023-11-28 12:46:18 25 4
gpt4 key购买 nike

我无法展示从数据库中获得的对象。我声明了包含要展示的项目的数组:

var tournaments = [TournamentItem]()

我的结构的 TournamentItem 初始化函数:

init(snapshot: FIRDataSnapshot!) {

key = snapshot.key
ref = snapshot.ref
type = snapshot.childSnapshotForPath("type").value as! String
name = snapshot.childSnapshotForPath("name").value as! String
numberOfParticipants = snapshot.childSnapshotForPath("numberOfParticipants").value as! Int
tournamentMode = snapshot.childSnapshotForPath("mode").value as! Bool
completed = snapshot.childSnapshotForPath("completed").value as! Bool
}

获取数据的函数如下所示:

func getTournamentListSnapshot() {

ref.observeEventType(.Value, withBlock: { snapshot in

//print("\(snapshot.key) -> \(snapshot.value)")


for item in snapshot.children {

let tournamentItem = TournamentItem(snapshot: item as! FIRDataSnapshot)
self.tournaments.append(tournamentItem)

}
if self.tournaments.isEmpty { //not a subject of discussion
self.showAlertOfEmptyTournamentsArray()
}

})
}

我在我的 ViewDidLoad 方法中调用它。问题是调用此方法后我的数组为空但 Firebase 数据库不是。我曾尝试调试整个过程,但找不到解决此问题的方法。

我的 TableViewController 委托(delegate)方法如下所示:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return self.tournaments.count
}

最佳答案

else 之后或可能在 else 中调用 tableView.reloadData():

if self.tournaments.isEmpty { 
self.showAlertOfEmptyTournamentsArray()
}
tableView.reloadData()

关于ios - 无法在 TableViewController 中显示来自 Firebase 数据库的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38015302/

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