我有一个Firebase数据库,可以在其中获取特定用户的快照。在Xcode中,我有一个显示用户的表格视图,当我选择一行时,快照将正确地打印在控制台中。当我尝试将快照数据传递到单击该行时显示的视图时,会出现问题,目前我无法从被单击的用户那里获取特定数据,而只能从其中一个获取数据。仅用户,这是其数据首先添加到数据库中的用户。
我知道传递值的原理如下:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let snapshot = rideRequest[indexPath.row]
performSegue(withIdentifier: "AppointmentRequest", sender: snapshot)
print(snapshot)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "AppointmentRequest" {
if let detailedRideVC = segue.destination as? AppoinemntRequestViewController {
if let snapshot = sender as? DataSnapshot {
if let rideDictionary = snapshot.value as? [String:AnyObject] {
if let email = rideDictionary["email"] as? String {
if let fullname = rideDictionary["fullname"] as? String {
if let status = rideDictionary["Accepted"] as? Bool {
detailedRideVC.requestEmail = email
detailedRideVC.email = email
detailedRideVC.status = status
detailedRideVC.fullname = fullname
// let location = CLLocationCoordinate2D(latitude: lat, longitude: long)
// detailedRideVC.requestLocation = location
// detailedRideVC.driverLocation = self.driverLocation
}
}
}
}
}
}
}
在第二个视图控制器中,我正在使用以下方法尝试显示快照中的数据,但是它不起作用:
func setupRequest(){
let uid = Auth.auth().currentUser?.uid
Database.database().reference().child("users").child(mainUser.key).child("AppointmentRequests").observe(.childAdded){ (snapshot) in
if let rideDictionary = snapshot.value as? [String:AnyObject] {
let email = rideDictionary["email"] as? String
let style = rideDictionary["styles"] as? String
let date = rideDictionary["date"] as? String
let fullname = rideDictionary["fullname"] as? String
let time = rideDictionary["time"] as! String
let shopname = rideDictionary["shopname"] as? String
let phone = rideDictionary["phone"] as? String
let cost = rideDictionary["cost"] as! Double
let clientImage = rideDictionary["clientID"] as? String
let status = rideDictionary["Accepted"] as? Bool
if self.status == true {
self.appointButton.isEnabled = false
self.appointButton.setTitle("Accepted", for: .normal)
} else {
self.appointButton.isEnabled = true
self.appointButton.setTitle("Accept", for: .normal)
}
self.shopName.text = email
self.appointmentDateTime.text = date
self.clientName.text = fullname
self.styleName.text = "Style:" + " " + style!
self.styleTime.text = time
self.ShopIs.text = shopname
self.styleCost.text = "USD" + "$" + "\(String(describing: cost))"
self.shopNumber.text = "Tel:" + " " + phone!
let ref = Storage.storage().reference(withPath: "users/" + clientImage! + "/avatar.jpeg");
ref.downloadURL(completion: { (url, error) in
if (url != nil)
{
self.clientProfilePic.kf.setImage(with: url);
}
})
}
}
在解决此问题方面的任何帮助将不胜感激。