用户位置引脚的自定义注释

时间:2017-07-08 15:19:33

标签: ios objective-c mkmapview

似乎可以更改用户位置注释图像。 也许有人可以看到我错在哪里......

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        NSString* AnnotationIdentifier = @"Annotation";
        MKAnnotationView *annoationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
        [annoationView setImage:[UIImage imageNamed:@"melocation"] ];
        return annoationView;
    }
}

1 个答案:

答案 0 :(得分:1)

您无法在无法出列时首次初始化注释:

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        static NSString* const kAnnotationIdentifier = @"Annotation";
        MKAnnotationView *annoationView = [mapView dequeueReusableAnnotationViewWithIdentifier:kAnnotationIdentifier];
        if (!annoationView) {
            annoationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kAnnotationIdentifier];
        }
        [annoationView setImage:[UIImage imageNamed:@"melocation"] ];
        return annoationView;
    }
    return nil;
}