我有不同位置的自定义图钉图像,我可以同时显示所有不同的图钉。但问题是,当我显示用户的当前位置时,所有引脚颜色都会改变。
这是代码:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[MapAnnotation class]]) {
MKAnnotationView *test=[[MKAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:@"AnnotationIdentifier"];
test.canShowCallout = YES;
// test.animatesDrop = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
test
.rightCalloutAccessoryView = rightButton;
switch (_pushpinTag) {
case 5:
test.image = [UIImage imageNamed:@"pushpin_green.png"];
break;
case 6:
test.image = [UIImage imageNamed:@"pushpin_blue.png"];
break;
case 7:
test.image = [UIImage imageNamed:@"pushpin_black.png"];
break;
case 8:
test.image = [UIImage imageNamed:@"pushpin_yellow.png"];
break;
case 3:
test.image = [UIImage imageNamed:@"pushpin_red.png"];
break;
default:
break;
}
return test;
}
}
现在在不同的按钮按下时,会显示不同的引脚(带有自定义图像)。假设我有绿色、蓝色、黑色和黄色的别针。我按下按钮显示绿色引脚,然后是蓝色,然后是黑色,所有引脚都显示在各自的图像中。但是当我按下按钮以显示用户当前位置时,所有 Pins 都变为最后一次按下的 Pin,即黑色。
这是显示用户当前位置的代码:
- (IBAction)currentLocationButton:(id)sender {
_mapView.showsUserLocation = YES;
[_mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];
}
谁能指出我在做什么错?
谢谢大家 :)