【问题标题】:Passing Values from Core data从核心数据传递值
【发布时间】:2020-10-09 04:17:08
【问题描述】:

我目前有核心数据,我想传递存在于持久存储中的选定引脚的坐标。所以我过滤了获取的对象并与视图注释坐标匹配。位置是我的实体的一个实例。我的代码如下:

 var location: Location!
 var latitude: Double = 0.0
 var longitude: Double = 0.0

 func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        performSegue(withIdentifier: "toPhotos", sender: self)
            let savedPins = fetchResultController.fetchedObjects!
        location = savedPins.filter({$0.latitude == view.annotation?.coordinate.latitude && $0.longitude == view.annotation?.coordinate.longitude}).first
            self.longitude = location.longitude
            self.latitude = location.latitude
    }

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let vc = segue.destination as? photoAlbumViewController {
            vc.dataController = dataController
            vc.longitude = longitude
            vc.latitude = latitude
}


当它转场时,它不会在第一次尝试时发送坐标,直到我第二次转回相册视图控制器,然后我才收到第一个坐标。

【问题讨论】:

    标签: ios swift iphone core-data


    【解决方案1】:

    看起来你在设置变量之前是在segueing。改成这样:

     func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
            let savedPins = fetchResultController.fetchedObjects!
            location = savedPins.filter({$0.latitude == view.annotation?.coordinate.latitude && $0.longitude == view.annotation?.coordinate.longitude}).first
            self.longitude = location.longitude
            self.latitude = location.latitude
    
            //moved to after setting the variables
            performSegue(withIdentifier: "toPhotos", sender: self)
    
        }
    

    【讨论】:

      猜你喜欢
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 2019-11-29
      • 2014-04-27
      • 1970-01-01
      相关资源
      最近更新 更多