ios - 通过 Firebase 从 MapKit 注释转至 UITableViewCell

标签 ios swift firebase mapkit

我正在尝试从 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/

相关文章:

ios - 当我为所有状态设置背景图像时,为什么我的 UISegmentedControl 段在 iOS 8 中突出显示?

ios - Firebase 查询未正确执行

ios - 如何禁用 UITableViewcell iOS 中特定部分的 uitableViewCell 选择

ios - 如何检测 UITextField 何时更改并触发警报?

ios - 通过参数判断子类类型,报错 "Use of undeclared type "。我能怎么做?

ios - 如何使用 Firebase 确保我的代码在 Swift 中按顺序运行?

ios - Unity Firebase Analytics 6.15.2 崩溃

ios - 使用 iOS 构建主机时 Xamarin 实际在做什么?

ios - Xcode 6.1.1 在设备上运行缓慢 "Copying Swift standard libraries"

ios - 在 coremltools 转换中指定 swift 版本