这应该是相当容易弄清楚我认为... 我有一个工作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