iOS Mapkit - Annotations disappear on map scroll/zoom

扶醉桌前 提交于 2020-01-15 06:36:27

问题


On initial load, the annotations show just fine. But if I scroll the map, they all disappear and the code is only called for the user location, not the other annotations in the viewForAnnotation delegate method.

Plot Pins

-(void)viewDidLoad{
     ...Download Coordinates and Data from Web here...
     [self.mapView addAnnotation:pin];
}

Delegate Method

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    //Player's Pin
    if([annotation class] == MKUserLocation.class) {
        return nil;
    }

    //Cluster Pin
    if([annotation isKindOfClass:[REVClusterPin class]]){
        REVClusterPin *pin = (REVClusterPin *)annotation;
        if( [pin nodeCount] > 0 ){
            pin.title = @"___";

            MKAnnotationView *annotationView  = (REVClusterAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"cluster"];

            if( !annotationView ){
                annotationView = (REVClusterAnnotationView*)
                [[REVClusterAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"cluster"];
            }

            annotationView.image = [UIImage imageNamed:@"cluster.png"];

            [(REVClusterAnnotationView*)annotationView setClusterText:
             [NSString stringWithFormat:@"%i",[pin nodeCount]]];

            annotationView.canShowCallout = NO;
            return annotationView;
        }
    }
    //Player Pin
    if([annotation isKindOfClass:[ZEPointAnnotation class]]){
        ZEPointAnnotation *pin = (ZEPointAnnotation *)annotation;
        MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
        if(!annotationView){
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"];
        }
        annotationView.canShowCallout = YES;
        annotationView.draggable = NO;

        ...Create Pin Data Here...

        return annotationView;
    }
    return nil;
}

回答1:


remove animations. that will solve your problem



来源:https://stackoverflow.com/questions/16328276/ios-mapkit-annotations-disappear-on-map-scroll-zoom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!