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