位置注释图像

问题描述:

我目前正在开发一个功能,用户可以点击地图注释并将其带到另一个屏幕上,该屏幕将显示该位置的图像。我正在使用Mapbox和tapOnCallout函数来继承另一个视图控制器(imageLocationViewController),它将保存图像视图。位置注释图像

我面临的问题是让这个imageLocationViewController知道哪个注释已被点击,因此应该显示哪个图像。我使用的是firebase来保存我的数据,并且在注释数据中我有一个包含相关图像的photoUrl。

我目前能够在我继续时打印注释和照片网址的相关名称。但是,一旦我在imageLocation视图控制器内,我相信我会丢失这些数据?

是否有人知道如何将这些数据传递到新的视图控制器,以便我可以将正确的photoUrl传递到图像视图。

这是我现在的代码,继续到imageLocationViewController。

func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) { 



    if let annotation = annotation as? SkateAnnotation { 



     self.performSegue(withIdentifier: "SkateImageSegue", sender: annotation.id) 

     print("YourAnnotation: \(annotation.photoUrl)") 

    } 
} 

更新**代号为赛格瑞

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "EditSaveSpotSegue" { 
     let destination = segue.destination as! EditSaveSpotViewController 
     destination.parkId = sender as! String 
    } 
} 
+0

[查看控制器之间传递数据]的可能的复制(https://*.com/questions/5210535/passing-data-between-view-controllers) – Chris

+0

我的问题是我的代码已经包含覆盖func准备(for segue:UIStoryboardSegue,发件人:任何?) – Cal

+0

你可以显示代码Cal? – Chris

我会设置一个局部变量时,您的MapView的委托功能火灾,你叫performSegue之前,然后使用该变量在prepareForSegue准备。见下面

var annotationId: String = "" 

func mapView(_ mapView: MGLMapView, tapOnCalloutFor annotation: MGLAnnotation) { 



    if let annotation = annotation as? SkateAnnotation { 


     annotationId = annotation.id 
     self.performSegue(withIdentifier: "SkateImageSegue", sender:self) 

     print("YourAnnotation: \(annotation.photoUrl)") 

    } 
} 


override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "EditSaveSpotSegue" { 
     let destination = segue.destination as! EditSaveSpotViewController 
     destination.parkId = annotationId 
    } 
} 
+1

好的,谢谢,当家时会试试这个 – Cal