0

I have implemented my MKMapViewDelegate, but for some reason my viewForAnnotation method is never called.

I can confirm that annotations are displayed on the MapView.

I've added an NSLog() to my method and the logging statement is never printed.

I know my class is definitely the MKMapViewDelegate because NSLog() statements in other MKMapViewDelegate methods are printed out.

I am also setting self.mapView.delegate = self in viewDidLoad

@interface MapViewController () <MKMapViewDelegate>
    @property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end

@implementation MapViewController

    @synthesize mapView = _mapView;
    @synthesize annotations = _annotations;


    -(void)setMapView:(MKMapView *)mapView
    {
        _mapView = mapView;
        [self updateMapView];
    }

    -(void)setAnnotations:(NSArray *)annotations
    {
        _annotations = annotations;
         [self updateMapView];
    }


    -(MKAnnotationView *)mapView:(MKMapView *)mapView
               viewForAnnotation:(id<MKAnnotation>)annotation
    {
     // For some reason this method is never called!!!!!!
     NSLog(@"This logging statement is never printed");

   }

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.mapView.delegate = self;
    }

    - (void)updateMapView
    {
        if (self.mapView.annotations) [self.mapView removeAnnotations:self.mapView.annotations];
        if (self.annotations) [self.mapView addAnnotations:self.annotations];
    }

@end
seedhead
  • 3,655
  • 4
  • 32
  • 38

2 Answers2

0

i think you are forgotten to hook up delegate outlet to files owner. right-click on it and hook up its delegate outlet to File's Owner.

Ravindra Bagale
  • 17,226
  • 9
  • 43
  • 70
0

A possible explanation is that there are no annotations.

Check the code that actually is adding the annotations to the mapView.

Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235