我有兩個批註數組。 從一個陣列我想要所有的綠色的針腳,從另一個我想要所有的紅色的針腳。 我通過這種方式加入數組: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