0

I have a MapViewController class and I set the

mapView.delegate = self

in viewDidLoad. When I first load the map, annotations are rendered correctly. However, after a refresh (e.g., after I hit a button in callout - say 'delete'), all the other pins lose their images and are rendered 'red'.

In my refresh method, I remove all annotations:

mapView.removeAnnotations(mapView.annotations)

and then recreate the annotations in the same manner I created them on initial load.

This code was working fine until today, when I upgraded to Swift 2.0. Was I simply lucky until now or am I missing a new piece of code?

I even tried forcing the pin to default to Green. But no matter what I do (set an image or change colour), post refresh, all pins are red :(

zevij
  • 2,416
  • 1
  • 23
  • 32

1 Answers1

0

found the bug in:

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

At some point during the day, I somehow changed the case where:

mapView.dequeueReusableAnnotationViewWithIdentifier(identifier) 

did not return nil and set the Annotation to MKPinAnnotationView. After a refresh, I dequeued the same object. Once rendered it defaulted to Red.

The solution was to handle a 'MKAnnotationView' objects only (whether my own sub-classess or default).

zevij
  • 2,416
  • 1
  • 23
  • 32