0

Alright, having an odd problem, my polyline that is set as an overlay for my map shows up fine unless I try to access an enumerated variable in the rendererForOverlay method.

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKGeodesicPolyline class]]) //If I change MKGeodesicPolyline to my subclass it won't render the overlay.
{
    CustomLine *poly = (CustomLine *)overlay;

    MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:(CustomLine *)overlay];


    //[poly testFunction]; //This will also cause overlay to not show

    //If I uncomment this it will cause the overlay to not show
    /*
    if (*poly.linecheck == Clear)
    {
        NSLog(@"Overlay should be red");
        renderer.strokeColor = [NSColor greenColor];
    }
    if (*poly.linecheck == Bad)
    {
        NSLog(@"Overlay should be green");
        renderer.strokeColor = [NSColor redColor];
    }
    */
    renderer.strokeColor = [NSColor redColor];
    //NSLog(@"polyline.linecheck %u",*poly.linecheck); //if this is uncommented it will also break the overlay.
    renderer.lineWidth = 3.0;
    return renderer;
}

return nil;

Here is my custom polyline's header.

#import <MapKit/MapKit.h>

enum linecheck
{
    Clear,
    Bad
};

@interface CustomLine : MKGeodesicPolyline
{

}

@property (readwrite) enum linecheck *linecheck;
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Steven Marlowe
  • 230
  • 2
  • 16
  • I also get this error each time I try to access the enumerated properties of the custom line. [MKGeodesicPolyline linecheck]: unrecognized selector sent to instance 0x61000028dd40 – Steven Marlowe Dec 03 '13 at 05:13
  • It seems to have nothing to do with the enumeration as if I remove enumeration entirely from the subclass and just add a test method, that will also break it. – Steven Marlowe Dec 03 '13 at 05:41
  • I was able to make this work by using the poly.title variable and setting it to @"good" or @"bad", then checking it with an if statement, but I would still rather do this through enumeration if that is possible. – Steven Marlowe Dec 03 '13 at 06:07
  • 1
    I don't think MKGeodesicPolyline supports being subclassed (see http://stackoverflow.com/questions/4949069/is-it-possible-to-inherit-from-mkpolyline which is regarding MKPolyline but MKGeodesicPolyline inherits from MKPolyline). That answer gives some other options (eg. associated object). Also, I would not declare the enum property as a _pointer_ since enum is basically just an int (primitive). Just declare as `enum linecheck linecheck;` (though I'd use different names for the enum and variable). –  Dec 03 '13 at 15:58

0 Answers0