下面是我的代码:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MapLocation *Annotation = annotation;
static NSString *identifier = @"MapLocation";
if ([annotation isKindOfClass:[MapLocation class]]) {
MKPinAnnotationView *annotationViewBus = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
MKPinAnnotationView *annotationViewTaxi = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
MKPinAnnotationView *annotationViewSam = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
MKPinAnnotationView *annotationViewMetro = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
//bus
if (!annotationViewBus ) {
annotationViewBus = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationViewBus.enabled = YES;
annotationViewBus.canShowCallout = YES;
if (busStatus==YES) {
annotationViewBus.image=[UIImage imageNamed:@"annotationBus.png"];//here we use a nice image instead of the default pins
return annotationViewBus;
}else {
annotationViewBus.annotation = annotation;
}
}
//taxi
if (!annotationViewTaxi ) {
annotationViewTaxi = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationViewTaxi.enabled = YES;
annotationViewTaxi.canShowCallout = YES;
if (taxiStatus==YES) {
annotationViewTaxi.image=[UIImage imageNamed:@"annotationTaxi.png"];//here we use a nice image instead of the default pins
// return annotationViewTaxi;
}else {
annotationViewTaxi.annotation = annotation;
}
}
//sam
if (!annotationViewSam ) {
annotationViewSam = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationViewSam.enabled = YES;
annotationViewSam.canShowCallout = YES;
if(samStatus==YES){
annotationViewSam.image=[UIImage imageNamed:@"annotationSam.png"];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:[Annotation name] forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(chatButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; //display another view
annotationViewSam.rightCalloutAccessoryView = rightButton;
// return annotationViewSam;
}else {
annotationViewSam.annotation = annotation;
}
}
//metro
if (!annotationViewMetro ) {
annotationViewMetro = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationViewMetro.enabled = YES;
annotationViewMetro.canShowCallout = YES;
if(metroStatus==YES){
annotationViewMetro.image=[UIImage imageNamed:@"annotationMetro.png"];
}else {
annotationViewMetro.annotation = annotation;
}
//return annotationViewMetro;
}
}
return nil;}
发布于 2014-04-03 12:33:06
您忘记了每个注释视图类型的return (MKAnnotationView *)。只需为每个类型添加返回AnnotationView即可。例如:
//metro
if (!annotationViewMetro ) {
annotationViewMetro = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationViewMetro.enabled = YES;
annotationViewMetro.canShowCallout = YES;
if(metroStatus==YES){
annotationViewMetro.image=[UIImage imageNamed:@"annotationMetro.png"];
}else {
annotationViewMetro.annotation = annotation;
}只需取消对此行的注释:
return annotationViewMetro;
}https://stackoverflow.com/questions/22826647
复制相似问题