可以在MKMapView上绘制的最大注释数(MKAnnotation)?

Shr*_*hri 5 iphone objective-c mkmapview mkannotation ios

我想在mapview上添加一些注释(arround 500),但它似乎显示的最大值为100.如果我超过100,则不会调用viewForAnnotation委托方法.但它适用于100以下的注释.

这是代码:(仅当annotationArray数组的数量小于101 时才有效)

_allPoints = [[NSMutableArray alloc] init];

NSString* responseFile = [[NSBundle mainBundle] pathForResource:@"Datafile" ofType:@"txt"];
NSData *sampleData = [NSData dataWithContentsOfFile:responseFile];  
if (sampleData) {  
    NSError* error;
    NSDictionary* json = [NSJSONSerialization 
                          JSONObjectWithData:sampleData

                          options:kNilOptions 
                          error:&error];

    NSArray* response = [json objectForKey:@"response"];
    for (NSDictionary *lineDict in response) {
        if ([[lineDict objectForKey:@"data"] isKindOfClass:[NSArray class]]) {
            SinglePoint *singlePoint = [[SinglePoint alloc] initWithDictionary:lineDict];
            [_allPoints addObject:singlePoint];
        }
        else {
            NSLog(@"Error");
        }
    }
}  


_mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[_mapView setDelegate:self];
[self.view addSubview:_mapView];

NSMutableArray *annotationArray = [[NSMutableArray alloc] init];
for (int i=0; i<[_allPoints count]; i++) {
    SinglePoint *singlePoint = [_allPoints objectAtIndex:i];
    NVPolylineAnnotation *annotation = [[NVPolylineAnnotation alloc] initWithPoint:singlePoint mapView:_mapView];
    [annotationArray addObject:annotation];
}
[_mapView addAnnotations:(NSArray *)annotationArray];

CLLocationCoordinate2D centerCoord = { 28.632747, 77.219982 };
[_mapView setCenterCoordinate:centerCoord zoomLevel:12 animated:NO];
Run Code Online (Sandbox Code Playgroud)

委托方法是:

编辑:根据评论,开始重用视图,但没有运气:(

if ([annotation isKindOfClass:[NVPolylineAnnotation class]]) {
    static NSString *viewIdentifier = @"annotationView";
    NVPolylineAnnotationView *annotationView = (NVPolylineAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:viewIdentifier];
    if (annotationView == nil) {
        annotationView = [[NVPolylineAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:viewIdentifier mapView:_mapView];
    }
    return annotationView;
}
return nil;
Run Code Online (Sandbox Code Playgroud)

我在文档或其他任何地方都找不到任何限制.这可能是记忆问题吗?

Shr*_*hri 1

终于能够找到问题所在。通过先设置mapView的中心,然后添加注释来解决。我仍然不知道为什么之前显示了 100 个注释(以及为什么只显示了 100 个注释)。感谢大家的建议和时间。

这是我更改的代码:-

_mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[_mapView setDelegate:self];
[self.view addSubview:_mapView];

CLLocationCoordinate2D centerCoord = { 28.632747, 77.219982 };
[_mapView setCenterCoordinate:centerCoord zoomLevel:12 animated:NO];

NSMutableArray *annotationArray = [[NSMutableArray alloc] init];
for (int i=0; i<[_allPoints count]; i++) {
    SinglePoint *singlePoint = [_allPoints objectAtIndex:i];
    NVPolylineAnnotation *annotation = [[NVPolylineAnnotation alloc] initWithPoint:singlePoint mapView:_mapView];
    [annotationArray addObject:annotation];
}
[_mapView addAnnotations:(NSArray *)annotationArray];
Run Code Online (Sandbox Code Playgroud)