Custom Annotation View's image does not appear on device build in MKMapView
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&g开发者_StackOverflow中文版t;)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?
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.
精彩评论