Один из buster12 должен отображать другое имя пользователя, с этой кнопкой связан правильный идентификатор, и если я перезагрузлю таблицу еще раз, все будет хорошо, но он не будет заполняться правильно в первый раз.
Я думаю, что я немного сузил его, поэтому, когда я напрямую вызываю список совпадений из firebase, используя что-то вроде функции fetchMatches () ниже всего Это хорошо. Но когда я впервые получаю указанные c идентификаторы совпадений для пользователя, а затем выполняю еще один вызов для этих совпадений, для функции fetchMyMatches () дела обстоят не так.
Вот две мои функции, получающие данные из Firebase :
func fetchMatches() {
let ref = Database.database().reference().child("completed_matches").queryLimited(toLast: 10)
ref.observe(.childAdded, with: { (snapshot) in
if let value = snapshot.value as? NSDictionary {
let matchT = Match2()
let active = value["active"] as? Int ?? 0
let submitter = value["submitter"] as? Int ?? 0
let winner = value["winner"] as? Int ?? 0
let team_1_player_1 = value["team_1_player_1"] as? String ?? "Player not found"
let team_1_player_2 = value["team_1_player_2"] as? String ?? "Player not found"
let team_2_player_1 = value["team_2_player_1"] as? String ?? "Player not found"
let team_2_player_2 = value["team_2_player_2"] as? String ?? "Player not found"
let team1_scores = value["team1_scores"] as? [Int] ?? [1, 1, 1, 1, 1]
let team2_scores = value["team2_scores"] as? [Int] ?? [1, 1, 1, 1, 1]
let time = value["time"] as? Double ?? Date().timeIntervalSince1970
matchT.active = active
matchT.winner = winner
matchT.submitter = submitter
matchT.team_1_player_1 = team_1_player_1
matchT.team_1_player_2 = team_1_player_2
matchT.team_2_player_1 = team_2_player_1
matchT.team_2_player_2 = team_2_player_2
matchT.team1_scores = team1_scores
matchT.team2_scores = team2_scores
matchT.matchId = snapshot.key
matchT.time = time
self.matches.append(matchT)
self.matches = self.matches.sorted { p1, p2 in
return (p1.time!) > (p2.time!)
}
DispatchQueue.main.async { self.tableView.reloadData()}
}
}, withCancel: nil)
}
func fetchMyMatches() {
guard let uid = Auth.auth().currentUser?.uid else {
return
}
let ref = Database.database().reference().child("user_matches").child(uid)
ref.observe(.childAdded, with: { (snapshot) in
let matchId = snapshot.key
let rootRef = Database.database().reference()
let query = rootRef.child("matches").child(matchId)
query.observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot)
if let value = snapshot.value as? NSDictionary {
let matchT = Match2()
let active = value["active"] as? Int ?? 0
let submitter = value["submitter"] as? Int ?? 0
let winner = value["winner"] as? Int ?? 0
let team_1_player_1 = value["team_1_player_1"] as? String ?? "Player not found"
let team_1_player_2 = value["team_1_player_2"] as? String ?? "Player not found"
let team_2_player_1 = value["team_2_player_1"] as? String ?? "Player not found"
let team_2_player_2 = value["team_2_player_2"] as? String ?? "Player not found"
let team1_scores = value["team1_scores"] as? [Int] ?? [1, 1, 1, 1, 1]
let team2_scores = value["team2_scores"] as? [Int] ?? [1, 1, 1, 1, 1]
let time = value["time"] as? Double ?? Date().timeIntervalSince1970
matchT.active = active
matchT.winner = winner
matchT.submitter = submitter
matchT.team_1_player_1 = team_1_player_1
matchT.team_1_player_2 = team_1_player_2
matchT.team_2_player_1 = team_2_player_1
matchT.team_2_player_2 = team_2_player_2
matchT.team1_scores = team1_scores
matchT.team2_scores = team2_scores
matchT.matchId = snapshot.key
matchT.time = time
DispatchQueue.main.async {
self.matches.append(matchT)
self.matches = self.matches.sorted { p1, p2 in
return (p1.time!) > (p2.time!)
}
self.tableView.reloadData()
}
}
})
}, withCancel: nil)
}