您好,我试图找出如何在tableView中显示同一用户的2辆汽车。有可能吗?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "driverRequestCell", for: indexPath)
if let email = Auth.auth().currentUser?.email {
Database.database().reference().child("Driver").queryOrdered(byChild: "email").queryEqual(toValue: email).observe(.childAdded, with: { (snapshot) in
if let driverRequestDictionary = snapshot.value as? [String:AnyObject] {
if let typeOfCar = driverRequestDictionary["car"] as? String {
cell.textLabel?.text = typeOfCar
}
}
})
}
return cell
}
答案 0 :(得分:1)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "driverRequestCell", for: indexPath)
if let email = Auth.auth().currentUser?.email {
Database.database().reference().child("Driver").queryOrdered(byChild: "email").queryEqual(toValue: email).observe(.childAdded, with: { (snapshot) in
//just add this line
let snapshot = self.driverRequests[indexPath.row]
if let driverRequestDictionary = snapshot.value as? [String:AnyObject] {
if let typeOfCar = driverRequestDictionary["car"] as? String {
cell.textLabel?.text = typeOfCar
}
}
})
}
return cell
}