Show title and subtitle in custom MKPinAnnotationView

I am using MKPinAnnotationView inside my application.

I set the MapView object as a delegate and using this code to customize my 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 } 

I get a custom AnnotationView as needed. However, I do not have the title and subtitle MKPointAnnotation .

I want to see the caption and subtitles for the gray dots. enter image description here

0
source share
1 answer

I redefined one function

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

I commented on this feature and got the titles and subtitles.

Updated Code

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

All Articles