Передача данных пользовательской аннотации - PullRequest
0 голосов
/ 24 ноября 2018

Как я могу передать пользовательские данные?Я использую эту функцию для выполнения перехода:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {}

class Custom : MKPointAnnotation { 
    var name:String?
    var time:String?
    var address:String?
}

Пожалуйста, помогите, если вы знаете, как это сделать!

1 Ответ

0 голосов
/ 24 ноября 2018

Можно попробовать

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    let anno = view.annotation as! Custom 
    print(anno.name)
    // then access the properties of anno and use them for the segue
    self.performSegue(withIdentifier:"SegueID",sender:anno)
} 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  if segue.identifier == "SegueID" {

    let des = segue.destination as! SecondVC
    des.ann = sender as! Custom 
  }
}

class SecondVC:UIViewController {

   @IBOutlet weak var lbl:UILabel!
   var ann:Custom!
    override func viewDidLoad() {
       super.viewDidLoad()
       self.lbl.text = ann.name
     }
}
...