MKAnnotationView图像在缩放或重新打开后取代

时间:2014-05-08 21:32:33

标签: ios mapkit mkannotationview

我用坐标解析Json并为每个注释视图下载单独的配置文件图像。当我在地图上缩放或移动时,我会看到在错误的地方替换了哪些图像。例如,我有一个坐标为111.1111,111.1111的注释视图。第一次图像和坐标是正确的,但在移动/缩放/重新打开带有地图的选项卡后,我看到其他注释视图,坐标为222.222,222.222,图像适用于111.111,111.1111。

(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{

    static NSString *identifier = @"SYLocationItem";
    if ([annotation isKindOfClass:[SYLocationItem class]]) {

        MKAnnotationView *annotationView = (MKAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if (annotationView == nil) {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            annotationView.enabled = YES;
            annotationView.canShowCallout = NO;

            SYJabberClient *client = [SYJabberClient sharedClient];
            [client retrieveProfileForUserWithEmail:[(SYLocationItem*)annotation email]
                                   withSuccessBlock:^(NSDictionary *dict, NSError *error) {
                                       if (dict) {

                                           UIImage *image = [dict objectForKey:@"imageFile"];

                                           UIImage *displayImage = [UIImage circularScaleNCrop:image
                                                                                      withRect:
                                                                    CGRectMake(0.0f,0.0f,30.0f,30.0f)];
                                           annotationView.image = displayImage;

                                       }
                                   }];
                    } else {
            annotationView.annotation = annotation;
        }

        return annotationView;
       }  
    return nil;      
}

现在我在这段代码中从本地获取图像,但如果下载图像我也有同样的问题。

0 个答案:

没有答案