我正在尝试从 MapKit Annotation (i) 按钮连接到 UITableViewCell。为了实现这一点,我使用以下代码:
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) 做了一个打印语句,这抛出了一个“意外发现 nil” Firebase 引用后的打印语句没有返回任何内容,所以我认为这是从 Firebase 开始的错误。 firebase 查询未运行,因此媒体永远不会获取值。我之前曾多次使用这种格式成功进行查询,但现在不起作用。有什么想法吗?
最佳答案
我将查询移至 map 函数内,并将 self.performSegue 包含在完成 block 中,现在它可以工作了。
关于ios - 通过 Firebase 从 MapKit 注释转至 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45089494/