在自定义 MKPinAnnotationView 中显示注释标题和副标题

Show Annotation Title and SubTitle in Custom MKPinAnnotationView

我在我的应用程序中使用 MKPinAnnotationView

我将 MapView object 设置为委托,并使用此代码自定义我的 AnnotationView

   func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

        if annotation is MKUserLocation {
            //return nil so map view draws "blue dot" for standard user location
            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!.image = UIImage(named:"store.jpg")
            pinView!.animatesDrop = true
            pinView!.pinTintColor = UIColor.darkGrayColor()
         }
        else {
            pinView!.annotation = annotation
        }

        return pinView
    }

我正在获取自定义 AnnotationView,因为我 required.However,我缺少 titleMKPointAnnotationsubtitle 的功能。

我希望看到灰点的标题和副标题。

我覆盖了一个函数

func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
        mapView.deselectAnnotation(view.annotation, animated: true)
    }

我把这个功能注释掉了,得到了标题和字幕。

更新代码

/*
 func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
 mapView.deselectAnnotation(view.annotation, animated: true)
 }
 */
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    if annotation is MKUserLocation {
        //return nil so map view draws "blue dot" for standard user location
        return nil
    }

    let reuseId = "pin"
    let  pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
    pinView.canShowCallout = true
    pinView.animatesDrop = true
    pinView.pinTintColor = UIColor.darkGrayColor()
    pinView.draggable = true
    pinView.accessibilityLabel = "hello"
    let btn = UIButton(type: .DetailDisclosure)
    pinView.rightCalloutAccessoryView = btn
    return pinView
}