데이터베이스에서 가져온 객체를 표시 할 수 없습니다. 나는 제시 내 항목을 포함하기위한 배열을 선언Firebase 데이터베이스의 항목을 TableViewController에 표시 할 수 없습니다.
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 데이터베이스가 호출되지 않습니다. 이 모든 것을 디버깅하려고했지만이 문제에 대한 해결책을 찾을 수 없습니다. 후
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tournaments.count
}
당신이'tableView.reloadData()를 호출하는 걸 잊었나요'후'의 경우 자기 .tournaments.isEmpty {// 토론 주제가 아님 self.showAlertOfEmptyTournamentsArray() }'? – Santosh
observeEventType에서 비동기 콜백을 수행 한 후에 배열을 확인하고 있습니까? –
@Santosh 여기에있는 경우입니다. 이제 올바르게 작동합니다. 감사합니다! – michalbanan