views:

35

answers:

1

I am using the iphone sdk and trying to use a custom image for my AnnotationView on my MKMapView. My approach works fine for another screen in my app, but for the problematic one, I see the image in the simulator but not on the device. I basically create a custom view like this:

@implementation CustomAnnotationView

- (id) initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [ super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier ])
    {
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];

        self.image = [UIImage imageNamed:@"MapIcon.png"];

    }
    return self;
}

@end

Then in the getViewForAnnotation method I do this:

    // attempt to reuse
    CustomAnnotationView* annotationView = (Custom AnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@""];

    // if reuse failed, create a new one
    if (annotationView == nil)
    {
        annotationView = [[Custom AnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@""];
    }

    return annotationView;

It works in the simulator but never in the device. If I stop using a custom view it places the red pin in both (i.e. it works). Has anyone seen a discrepancy like this?

A: 

Wow. I discovered that the problem was that MapIcon.png does not exist. That explains why it did not work on the device, but it doesn't explain how I managed to see the icon in the simulator. Perhaps in some twisted way it found the MapIconLocale.png file which is in the project. Or could there be some trace asset in the project because I used to have a MapIcon.png weeks ago and removed it (a copy somehow)?

Either way, having the correctly named image obviously fixed it.

Joey
I have sometimes found old resources from previous builds that haven't been removed - I always uninstall the app from the simulator and re-install from scratch when I get these kinds of bugs :)
deanWombourne