これはかなりわかりやすいはずです。 マップ上にピン番号の付いた一連のピンマーカーが表示されます。私はplistからピンのイメージを呼んでいますが、ピンが落ちると、それらはすべて最後のピンの番号と同じ番号になります。 (1,2,3 ..の代わりに)mapkitの複数のポイントが異なる画像で表示される
違反コードは以下の通りです。私はそれを修正する方法がわかりません...ありがとうございます。
NSString *path = [[NSBundle mainBundle] pathForResource:[route objectForKey:NAME_KEY] ofType:@"plist"];
NSMutableArray* array = [[NSMutableArray alloc] initWithContentsOfFile:path];
points = array;
for (NSDictionary *routeDict in points){
AllAnnotations *Annotation = [[AllAnnotations alloc] initWithDictionary:routeDict];
[mapView addAnnotation:Annotation];
[Annotation release];
}
for (NSDictionary *routeDict in points){
NSString *first = [routeDict objectForKey: POINT_KEY];
NSString *getNum = [routeDict objectForKey: COLOR_KEY];
NSString *again = [getNum stringByAppendingString:first];
NSString *imgValue = [again stringByAppendingString:@".png"];
annotationView.image = [UIImage imageNamed:imgValue];
}
annotationView.canShowCallout = YES;
AllAnnotations.m
------------------------------------------------------------------------------------------
- (id) initWithDictionary:(NSDictionary *) dict
{
self = [super init];
if (self != nil) {
coordinate.latitude = [[dict objectForKey:@"latitude"] doubleValue];
coordinate.longitude = [[dict objectForKey:@"longitude"] doubleValue];
self.title = [dict objectForKey:@"name"];
self.subtitle = [dict objectForKey:@"subname"];
}
return self;
}
感謝を。私はAllAnnotations.mファイルを追加するために上で編集しました...辞書はプロパティとして追加されません。私はこれを試してみると空白のマップが得られるので、Annotations.mファイルに追加する必要があるものは何か分かりません。 – alittlelost
あなたが示したコードで、最初の行から最初のfor-loopまでがviewDidLoadにあることを確認できますか? 2番目のfor-loopとそれ以降の行はviewForAnnotationにありますか? – Anna
はい、それは正しいです – alittlelost