【发布时间】:2014-02-25 09:26:18
【问题描述】:
我有两个注释数组。 从一个阵列中,我想要所有绿色引脚,而从另一个阵列中,我想要所有红色引脚。 我正在通过这种方式添加数组:
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;
}
但是这样我得到了相同颜色的别针。但我想要两种颜色。
【问题讨论】:
-
对绿色引脚颜色和红色引脚颜色使用不同的重用标识符。并且使用 dequeueReusableAnnotationViewWithIdentifier:identifier 方法也使用 initWithAnnotation:reuseIdentifier: 方法并根据注解为每种颜色赋予不同的reuseidentifier。
-
@insane-36 你能告诉我怎么做吗???
-
我将在下面的示例中向您展示。顺便说一句,您不必使用两个不同的重用标识符。
-
@insane-36...例子在哪里?
-
您好,您解决了这个问题吗?我已经向您展示了下面的示例。
标签: ios iphone mkmapview mkannotation mkannotationview