मै मैप्यूव्यू पर कई एनोटेशन (लगभग 500) जोड़ना चाहता हूं लेकिन अधिकतम दिखने वाला लगता है 100. यदि मैं 100 से अधिक, व्यूफोरऑनोटेशन प्रतिनिधि विधि नहीं कहा जाता है। लेकिन यह नीचे 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];
प्रतिनिधि विधि है:
संपादित करें: टिप्पणियों के अनुसार, दृश्य का पुन: उपयोग करना शुरू किया लेकिन बिना किस्मत के :(
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;
मुझे प्रलेखन या कहीं और में कोई प्रतिबंध नहीं मिला। क्या यह स्मृति समस्या हो सकती है?
क्या अगर आप अपने 'annotationArray' को' allPoints' 500 बार में पहली वस्तु जोड़ना होता है? –
क्या 'NVPolylineAnotation' के लिए स्रोत कोड प्रदान करना संभव है? –