获取在地图上单击的注释标题

时间:2016-01-13 21:59:30

标签: ios xcode swift2

嗨我有这个代码用于点击annotationView,当点击注释我想知道注释的标题是什么时,这可能吗?

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

        if (control as? UIButton)?.buttonType == UIButtonType.DetailDisclosure {
            mapView.deselectAnnotation(view.annotation, animated: false)
            performSegueWithIdentifier("moreInfo", sender: view)
        }
    }

func setPins(){
        for restaurant in restaurantObjects{
            let annotation = MKPointAnnotation()
            annotation.coordinate = CLLocationCoordinate2DMake(restaurant.latitude, restaurant.longitude)
            annotation.title = restaurant.name
            annotation.subtitle = "This is a phoneStation"
            mapRestaurants.addAnnotation(annotation)
        }
    }

1 个答案:

答案 0 :(得分:0)

找到解决方案:

func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
        if (control as? UIButton)?.buttonType == UIButtonType.DetailDisclosure {
            var title = view.annotation?.title
            print(title)
            mapView.deselectAnnotation(view.annotation, animated: false)
            performSegueWithIdentifier("moreInfo", sender: view)
        }
    }