MKMapView - rendererForOverlay not called

user2734323 picture user2734323 · Sep 20, 2013 · Viewed 12.5k times · Source

I recently started learning objectiveC and started developing an app in iOS6.

Now, I am trying to convert it for iOS7 and facing issues with MKMap.

In iOS6, I was using viewForOverlay.

In iOS7, I am changing it to renderForOverlay. But, my application is not calling mapView:rendererForOverlay. Below is my code. Appreciate your help.

- (void) drawPolyline:(NSArray *)locations
{
    [mapView setDelegate:self];
    ...
    ...

    self.polyline = [MKPolyline polylineWithCoordinates:locationCoordinate2DArray count:numberOfLocations];
    free(locationCoordinate2DArray);
    [mapView addOverlay:self.polyline];
    [mapView setNeedsDisplay];
}

- (MKOverlayRenderer*)mapView:(MKMapView*)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineRenderer* lineView = [[MKPolylineRenderer alloc] initWithPolyline:self.polyline];
    lineView.strokeColor = [UIColor blueColor];
    lineView.lineWidth = 7;
    return lineView;
}

Answer

Mike Petrogeorge picture Mike Petrogeorge · Sep 21, 2013

I am assuming that you did declare the MKMapViewDelegate delegate in your header file via the @interface statement:

However, did you assign the delegate in the viewDidLoad (or where you think its appropriate) method?

self.mapView.delegate = self;