viewForAnnotation:(id<MKAnnotation>) annotation
メソッドを実装してMKMapViewDelegateプロトコルに準拠するUIViewサブクラスにMKMapViewインスタンスがあります。となっているコード:MKAnnotationViewイメージが表示されない
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:[DriverLocation class]]) {
MKAnnotationView* a = [self.map dequeueReusableAnnotationViewWithIdentifier:@"driverView"];
if (a == nil) {
MKAnnotationView* a = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"driverView"];
a.enabled = YES;
a.image = [UIImage imageNamed:@"car.png"];
}
return a;
}
return nil;
}
画像が正しくロードされていない - ロードされたイメージのプロパティがゼロの高さと幅を有し、MKAnnotationViewインスタンスAの寸法もゼロです。
画像は4Kb png 32ピクセル×32ピクセルです。
イメージがシミュレータのルート.appディレクトリにコピーされたことを確認できます。
これがロードされていない理由についてのお手伝いをいただければ幸いです。
申し訳ありません:あなたはに
MKAnnotationView* a = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"driverView"];
を変更する必要があります。私はアホです。私は2つの変数を作成します。if文のインスタンス化はa = ... not MKAnnotationView * aでなければなりません。 – Owen