這應該是相當容易弄清楚我認爲... 我有一個工作mapview,它將一系列編號引腳標記放到地圖上。我打電話給plist的pin圖像,但是,當引腳掉落時,它們的數量都與最後一個引腳的數量相同。 (而不是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 2010-12-13 20:41:13
您可以確認在您顯示的代碼中:從第一行到第一個for循環是在viewDidLoad中?第二個for循環和之後的行在viewForAnnotation中? – Anna 2010-12-13 20:47:37
是的,這是正確的 – alittlelost 2010-12-13 21:25:58