传递数据以从注释中分离出来?

Passing data to segue from annotation?

我有一个带有注释的 mapView,这些注释是使用来自 CloudKit 的数据创建的。我使用注释中的信息按钮在点击按钮时调用 segue。

我知道我可以像这样轻松传递标题和副标题..

func mapView(mapView: MKMapView, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {

    let detailTitle = annotationView.annotation.title

    performSegueWithIdentifier("fromMap", sender: self)

}

我的问题是我需要发送的不仅仅是 MKAnnotation 视图中的数据。 CloudKit 记录中还有一些其他字段需要通过 segue 传递给详细信息控制器,但我一辈子都不知道该怎么做。

使用 tableView 很容易,因为您有 indexPath 信息,但据我所知,您没有从注释中获得该信息。

我已经浏览了所有可以在网上找到的帖子和信息,但我仍然卡住了。

如有任何帮助,我们将不胜感激。

您可以使用 tuple 发送多个对象并从目标视图控制器捕获它们

func mapView(mapView: MKMapView, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
  let detailTitle = annotationView.annotation.title
  performSegueWithIdentifier("fromMap", sender: (annotation.title, annotation.subtitle, annotation.address))
}