iOS MapView的注释显示不正确的图标图像

时间:2015-02-17 19:15:07

标签: ios uiimageview mkmapview mkannotation

在我的iOS应用程序中,我有一个MapView,我有一个自定义注释(扩展MKAnnotation)。

我为每个注释设置了一个图标图像,具体取决于它的类型。当我第一次加载地图视图时,所有图像都是正确的,但当您移动图像时,图像开始变为不同的图像。

它几乎就像操作系统正在回收注释并在它们重新出现在屏幕上时将它们带回来,但图像错误。

有谁知道如何解决这个问题?谢谢你的帮助。

这是我的委托方法:

    -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
    if ([annotation isKindOfClass:[CustomAnnotationView class]]) {
        CustomAnnotationView *customAnnotation = (CustomAnnotationView *)annotation;
        MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"CustomAnnotation"];
        if (annotationView == nil) {
            annotationView = customAnnotation.annotationView;
        }
        else{
            annotationView.annotation = annotation;
        }

        return annotationView;
    }
    else{
        return nil;
    }
}

这是我的对象的样子:

@interface CustomAnnotationView : NSObject<MKAnnotation>

@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;
@property (copy, nonatomic) NSString *title;
@property (copy, nonatomic) NSString *subtitle;
@property (weak, nonatomic) Thing *thing;

-(id)init:(Thing *)thing;
-(MKAnnotationView *) annotationView;
-(void)setDistance:(CLLocationCoordinate2D)point;
@end

0 个答案:

没有答案