我正在创建自定义注释,我试图使用dequeueReusableAnnotation。 引脚之间的区别是用于引脚图像的png。viewForAnnotation中的注释标识符
我已经创建myAnnotation类和我使用的时候,我创建注释此代码:在viewForAnnotation
if([category isEqualToString:@"anti-social-behaviour"]){
[email protected]"A.png";
}
else
if([category isEqualToString:@"burglary"]){
[email protected]"B.png";
}
else....
现在:
- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if ([annotation class] == MKUserLocation.class) {
return nil;
}
static NSString *identifier = @"myPin";
MKPinAnnotationView *pinView = nil;
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (pinView == nil)
{
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:[(Annotation*)annotation annotationImg]];
}
return pinView;
}
我知道我必须不知何故使用标识符,但我没有弄明白。 现在的问题是,我第一次加载的引脚很好,第二个图像弄乱了。 有什么建议吗?
外面我应该使用大量的if/else给每个它的类别标注? – BlackM