Ios 使用Firebase从MapKit注释切换到UITableViewCell
我正在尝试从MapKit注释(I)按钮切换到UITableViewCell。为此,我使用以下代码:Ios 使用Firebase从MapKit注释切换到UITableViewCell,ios,swift,firebase,mapkit,Ios,Swift,Firebase,Mapkit,我正在尝试从MapKit注释(I)按钮切换到UITableViewCell。为此,我使用以下代码: func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { let annotation = view.annotation as! MKPointAnnotation let ui
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
let annotation = view.annotation as! MKPointAnnotation
let uid = annotation.title
self.userkey = uid!
self.performSegue(withIdentifier: "showDetailFromMap", sender: self)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDetailFromMap" {
let detailTVC = segue.destination as! MediaDetailTableViewController
let value = self.userkey
print(value)
let ref2 = DatabaseReference.media.reference()
let query2 = ref2.queryOrdered(byChild: "uid").queryEqual(toValue: (value))
query2.observe(.childAdded, with: { snapshot in
let media = Media(dictionary: snapshot.value as! [String : Any])
print(snapshot.value)
self.media1 = media
})
detailTVC.media = media1
detailTVC.currentUser = currentUser
}
}
我在tableViewController的cellForRow中作为print(user.uid)生成了一个print语句,这将抛出一个“意外发现nil”。firebase引用之后的print语句没有返回任何内容,因此我认为这是从firebase错误开始的。firebase查询未运行,因此媒体从未获取值。我以前多次使用这种格式成功地进行查询,但现在它不起作用。知道为什么吗?我将查询移到map函数中,并将self.performsgue包含在完成块中,现在可以使用了