Ios Swift-通过“披露”按钮将数据从mapkit注释传递到另一个视图

Ios Swift-通过“披露”按钮将数据从mapkit注释传递到另一个视图,ios,swift,annotations,mapkit,callouts,Ios,Swift,Annotations,Mapkit,Callouts,我有一张带有注释的地图,单击图钉后,标注显示为注释标题和一个公开按钮。当我点击按钮时,序列被触发,我移动到另一个视图。如何确定单击的注释,或将标题传递给其他视图 func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { if annotation is MKUserLocation{ return

我有一张带有注释的地图,单击图钉后,标注显示为注释标题和一个公开按钮。当我点击按钮时,序列被触发,我移动到另一个视图。如何确定单击的注释,或将标题传递给其他视图

func mapView(mapView: MKMapView!,
    viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
        if annotation is MKUserLocation{
            return nil
        }

        let reuseId = "pin"

        var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView

        if(pinView == nil){
            pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
            pinView!.canShowCallout = true
            pinView!.animatesDrop = true
            pinView!.pinColor = .Red

            var calloutButton = UIButton.buttonWithType(.DetailDisclosure) as UIButton
            pinView!.rightCalloutAccessoryView = calloutButton
        } else {
            pinView!.annotation = annotation
        }
        return pinView!
}

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

    if control == annotationView.rightCalloutAccessoryView {
        performSegueWithIdentifier("Detail", sender: self)
    }
}

谢谢

如果注释标题不同,您可以使用
annotation
属性的
MKAnnotation
title
查找接点

 annotationView.annotation.title
返回
String
。比较
String
进行差异化

pinview

pinView!.tag //set tag for each pin in `viewForAnnotation` method


尝试将标题保存到NSUserDefaults,然后在新视图中抓取该对象。这是我使用的方法

 func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
    if control == view.rightCalloutAccessoryView{


        println(view.annotation.title) // annotation's title

        let title = view.annotation.title


        NSUserDefaults.standardUserDefaults().setObject(title, forKey: "Title")


        var InfoView = self.storyboard?.instantiateViewControllerWithIdentifier("Spot") as! UIViewController
将标题保存到NSUserDefaults后,您只需在新的“InfoView或您所称的任何内容”中抓取对象,如下所示
let spotTitle=NSUserDefaults.standardUserDefaults().objectForKey(“spotTitle”)as!字符串


希望这有助于

在CalloutAccessoryControl中,annotationView.annotation将为您提供注释对象。调用performsgue时,将sender设置为annotationView,而不是self。参见示例(在Objective-C中,但转换为Swift应该不会太困难)。我不建议使用标记方法。
 func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
    if control == view.rightCalloutAccessoryView{


        println(view.annotation.title) // annotation's title

        let title = view.annotation.title


        NSUserDefaults.standardUserDefaults().setObject(title, forKey: "Title")


        var InfoView = self.storyboard?.instantiateViewControllerWithIdentifier("Spot") as! UIViewController