このチュートリアルに従おうとしています:http ://www.switchonthecode.com/tutorials/building-an-earthquake-monitor-for-iphone-using-mapkit
アイコンがすべての適切な場所(および適切な番号)に表示されており、画像も表示されています。(ただし、これは常に同じ画像です。これは、条件付きif(self.marker.type == "nzpost"が機能しないためです。これは、typeが常にnullであるためです(initWithAnnotation()内のマーカーオブジェクトのすべてのプロパティも同様です)。 。何らかの理由で、プロパティはすべてnullです。
注釈ビューインターフェイス:
@interface PayMarkerAnnotationView : MKAnnotationView {
PaymentMarker *marker;
}
@property (strong, nonatomic) IBOutlet PaymentMarker *marker;
@end
注釈付きの初期化:(ここで、self.marker.typeに値を指定する必要があります。
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
if(self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) {
self.backgroundColor = [UIColor clearColor];
NSString* imageName = [[NSString alloc] init];
if([self.marker.type isEqualToString:@"nzpost"]) {
imageName = @"icon-map-post.png";
} else {
imageName = @"icon-map-incharge.png";
}
self.image = [UIImage imageNamed:imageName];
}
return self;
}
マップビュー:
- (MKAnnotationView *)mapView:(MKMapView *)lmapView viewForAnnotation:(id <MKAnnotation>)annotation {
PayMarkerAnnotationView *markerView = (PayMarkerAnnotationView *)[lmapView dequeueReusableAnnotationViewWithIdentifier:@"markerView"];
if(markerView == nil) {
markerView = [[PayMarkerAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"markerView"];
}
markerView.annotation = annotation;
return markerView;
}
にマーカーを追加する
-(void)renderPaymentMarkers
{
[self.map addAnnotations: nzPostMarkers];
[self.map addAnnotations: inChargeMarkers];
}
Marker class:
@interface PaymentMarker : NSObject <MKAnnotation> {
NSString* type;
NSString* description;
float latitude;
float longitude;}
@property (nonatomic) NSString* description;
@property (nonatomic) NSString* type;
@property (nonatomic) float latitude;
@property (nonatomic) float longitude;
//MKAnnotation
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@end