Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 1个用户具有2个firebase数据库信息_Xcode_Uitableview_Firebase_Firebase Realtime Database - Fatal编程技术网

Xcode 1个用户具有2个firebase数据库信息

Xcode 1个用户具有2个firebase数据库信息,xcode,uitableview,firebase,firebase-realtime-database,Xcode,Uitableview,Firebase,Firebase Realtime Database,您好,我想弄清楚如何在tableView中显示同一用户的两辆车。可能吗 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "driverRequestCell", for: indexPath) if let e

您好,我想弄清楚如何在tableView中显示同一用户的两辆车。可能吗

   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

}

这肯定是可能的。你能展示一下你已经尝试过的吗?嗨,弗兰克凡帕夫伦,很抱歉回复晚了。我认为我们的时区不同。我更新了我上面问的问题。我添加了我使用的代码。希望很快收到你的来信。谢谢Firebase代码看起来不错。由于您观察到
.childAdded
您的封闭块将被调用两次:每辆车调用一次。但是由于您只有一个文本标签,第二个
typeOfCar
将替换第一个。这是否意味着我应该更改observe.childAdded?一点也不。由于您有两辆匹配查询的汽车,因此只需调用两次即可。但是您需要在表中使用两个单元格(每辆车一个),或者将两辆车的信息添加到一个单元格中。
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

}