我有两个批注数组。 从一个阵列我想要所有的绿色的针脚,从另一个我想要所有的红色的针脚。 我通过这种方式加入数组:MapView使用differenet颜色添加多个注释
fromSelectedTab=False;
[userMap addAnnotations:greenArray];
fromSelectedTab=TRUE;
[userMap addAnnotations:redArray];
和viewforannotation我这样做:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// static NSString *identifier = @"myAnnotation";
// // annotation=(MapObjects*)annotation;
// MKPinAnnotationView * annotationView = (MKPinAnnotationView*)[userMap dequeueReusableAnnotationViewWithIdentifier:identifier];
// if(!annotationView){
MKPinAnnotationView * annotationView= [[MKPinAnnotationView alloc] init ];//WithAnnotation:annotation reuseIdentifier:nil];
//annotationView.tintColor=[UIColor blackColor];
annotationView.annotation=annotation;
NSLog(@"flag%d",fromSelectedTab);
if (fromSelectedTab==TRUE) {
annotationView.pinColor = MKPinAnnotationColorRed;
}
else{
annotationView.pinColor = MKPinAnnotationColorGreen;
// fromSelectedTab=TRUE;
}
annotationView.animatesDrop = NO;
annotationView.canShowCallout = YES;
//fromSelectedTab=FALSE;
// else {
// annotationView.annotation = annotation;
// }
//annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return annotationView;
}
但这种方式我收到相同颜色的针。但我想用两种颜色。
使用不同的重用标识符n针脚颜色和红色针脚颜色。并使用dequeueReusableAnnotationViewWithIdentifier:标识符方法也使用initWithAnnotation:reuseIdentifier:方法,并根据注释为每种颜色提供不同的重用标识符。 – Sandeep
@疯狂-36你能告诉我如何? – jayesh
我会在下面的例子中给你看。顺便说一句,你不必使用两个不同的重用标识符。 – Sandeep