1个用户拥有2个Firebase数据库信息

时间:2018-09-24 15:29:57

标签: xcode uitableview firebase firebase-realtime-database

sample image

您好,我试图找出如何在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

}

1 个答案:

答案 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

}