MKAnnotation callout view not working

I'm trying to implement a callout view for an MKAnnotationView.

Just as a start, I've built the view in the Interface Builder and subclassed MKAnnotationView as follows:


class CampfireView: MKAnnotationView

{

init(annotation: MKAnnotation, calloutView: UIView)

{

super.init(annotation: annotation, reuseIdentifier: "Campfire")

leftCalloutAccessoryView = calloutView

}


required init(coder: NSCoder)

{ super.init(coder: coder)! }

}


When the Campfire annotation is added, my ViewController handles the callback as follows:


func mapView(_ mapView: MKMapView, viewFor: MKAnnotation) -> MKAnnotationView?

{

let site = viewFor as! Site

let icon = site.fIcon

let reuse = mapView.dequeueReusableAnnotationView(withIdentifier: icon)

if reuse != nil { return reuse }

switch icon

{

case "Campfire":

let view = CampfireView(annotation: viewFor, calloutView: fCampfireView)

view.image = UIImage(named: icon) // BREAKPOINT

return view

default:

let view = MKAnnotationView(annotation:site, reuseIdentifier:icon)

view.image = UIImage(named: icon)

return view

}

}


No callout view appears when the annotation is tapped.


At the breakpoint (when the annotation is added) the debugger doesn't even show the MKAnnotationView's variables (of course, I'm interested in leftCalloutAccessoryView) although it did when inside the CampfireView initializer. I feel like I must be missing something basic about subclassing and/or the way that these callout views are supposed to work. Any help greatly appreciated.


Steve.

Apologies - The Location and Maps Programming Guide covers this, and it's clearly not as straightforward as I had hoped.

MKAnnotation callout view not working
 
 
Q