0

I have a working extention of MKOverlayView class with the mapview delegate triggering and executing the – mapView:viewForOverlay: delegate method perfectly. So to move away from a deprecated class, I have changed my extention of MKOverlayView to extend MKOverlayRenderer... Doing this, but leaving the viewForOverlay method in place works fine....

However the delegate method viewForOverlay is deprecated as well, so I replace it with the rendererForOverlay method to be in alignment with the non Deprecated API and it NEVER gets triggered...

The delegate for the MapView is properly hooked up, (which is proven by the viewForOverlay working, but when I replace this method with rendererForOverlay, which is its replacement, it never ever triggers... and as such my overlay doesn't get drawn. This makes no sense to me.

I am very much at a loss, the only thing different between versions that work, and versions that don't, is this method. Even after I changed my class from being an MKOverlayView extention to an MKOverlayRenderer extention the overlay still draws as long as the viewForOverlay method exists in the delegate, it gets called. But the moment I replace the viewForOverlay delegate method for the rendererForOverlay method nada.

Here is the code:

This method works properly whether the class MapOverlayView is extending MKOverlayView or MKOverlayRenderer, either one and this delegate method is called and the overlay is rendered.

-(MKOverlayView*)mapView:(MKMapView*)mapView viewForOverlay:(id<MKOverlay>) overlay{
 MyMapOverlay *mapOverlay = overlay;
 MapOverlayView *mapOverlayView = [[MapOverlayView alloc] initWithOverlay:mapOverlay];
 return mapOverlayView;
 }

For this method I make sure MapOverlayView is always extending MKOverlayRenderer, but the delegate method NEVER gets triggered.. Why would the above deprecated method always get called and work, but the below proper non deprecated method never get triggered?

-(MKOverlayRenderer*)mapView:(MKMapView*)mapView rendererForOverlay:(id<MKOverlay>) overlay{
 MyMapOverlay *mapOverlay = overlay;
 MapOverlayView *mapOverlayView = [[MapOverlayView alloc] initWithOverlay:mapOverlay];
 return mapOverlayView;
 }
Speckpgh
  • 3,332
  • 1
  • 28
  • 46
  • 1
    it's a lower case 'm' on the method name, mapView:... not MapView:... – manecosta May 12 '14 at 13:57
  • It is lowercase in the code, I transposed it wrong here... I will edit... so problem still exists. – Speckpgh May 12 '14 at 14:02
  • are you testing on iOS7 simulator/phone? – manecosta May 12 '14 at 14:36
  • One thing you're messing up a bit is the delegate of the MKMapView being an MKOverlayView/Renderer. While the delegate just needs to implement the protocol methods independent of what it is, there is a conceptual difference between an object responsible for returning Views/Renderers and the Views/Renderers themselves, and you're mixing both. – manecosta May 12 '14 at 14:44
  • I am currently testing on simulator. I appreciate the conceptual difference, but the fact the delegate is not being called is the issue at hand. – Speckpgh May 12 '14 at 14:52

1 Answers1

0

I found out that the rendererForOverlay method gets called when the Overlay object is within the display map boundaries. You need to scroll the map to where the overlay should be displayed to trigger the call.

kudos
  • 101
  • 3