以下の何が間違っているかについての提案をいただければ幸いです。
次のコードを使用して、注釈にカスタム イメージを追加しています。
- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isMemberOfClass:[MKUserLocation class]])
{
return nil;
}
if ([annotation isMemberOfClass:[SpectatorPin class]])
{
SpectatorPin *sp = (SpectatorPin *)annotation;
MKAnnotationView *view = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"specPin"];
if (view == nil) {
view = [[[MKPinAnnotationView alloc] initWithAnnotation:sp reuseIdentifier:@"specPin"] autorelease];
}
view.image = [UIImage imageNamed:@"mylocation20x20.png"];
view.canShowCallout = YES;
view.annotation=annotation;
return view;
}
//Should not get here
return nil;
}
最初はちゃんと画像が表示されています。
マップ タイプ (標準、衛星、ハイブリッド) を変更するセグメント コントロールがあります。標準がデフォルトです。衛星を選択するとすぐに、画像がピンに変わります。mapView:viewforAnnotation メソッドは再度呼び出されません。
よろしく、
ジム