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

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

我将MapView对象设置为委托,并使用此代码来定制我的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按照我的要求。但是,我错过了titleMKPointAnnotation subtitleMKPointAnnotation

我希望看到灰点的标题和副标题。 在这里输入图像说明

我重写了一个函数

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

我评论了这个function,并获得了标题和字幕。

更新的代码

 /* 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 }