2011-08-09 50 views
0

我知道你可以使用像创建自定义的注解视图:更改MKAnnotationView自定义图像?

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    MKPinAnnotationView *annotationView = [[[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomAnnotation"] autorelease];  
    annotationView.image = [UIImage imageNamed:@"customPin.png"]; 
    return annotationView; 
} 

..但我怎么改变形象在我的代码其他部分。(已与上面创建之后)?

回答

2

你可能不需要这个答案了,但仍然没有答案。我通常做的是添加一个属性到注释中,告诉哪个图像应该被使用。它可以是BOOL,UIImage或几乎任何你喜欢的。

viewForAnnotation,我检查该值并设置适当的图像。

每当我想更新的形象,我改变属性的值,和我删除和添加注释:

[theMapView removeAnnotation: myAnnotation]; 
[theMapView addAnnotation: myAnnotation]; 

通过这种方式,注释重新绘制。

相关问题