Map Issue for MKAnnotationView in iOS 7 and iOS 8

131 views Asked by At

I use iOS SDK 8 and having problem to display annotation for certain locations but it is working fine for some locations.

For those failed location, it keeps looping at if (pinView == nil) and the app will quit unexpectedly, any idea for the root caused?

 - (void)populateAllLocation {
 self.locations = [selectedCountry_.locations allObjects];

 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"latitude != nil &&   longitude != nil"];
 self.locations = [[selectedCountry_.locations filteredSetUsingPredicate:predicate] allObjects];

[mapView_ addAnnotations:locations_];
[self centralizeMap];
}

-(MKAnnotationView *)mapView:(MKMapView *)mapView
        viewForAnnotation:(id<MKAnnotation>)annotation {
if ([annotation isKindOfClass:MKUserLocation.class]) {
static NSString *PinIdentifier = @"UserLocationPin";
MKAnnotationView *pinView =
[mapView_ dequeueReusableAnnotationViewWithIdentifier:PinIdentifier];
if (pinView == nil) {
  pinView =
  [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                reuseIdentifier:PinIdentifier] autorelease];
  pinView.canShowCallout = YES;
  pinView.image = [UIImage imageNamed:@"mylocation_pin"];
}

[self populateAllLocation];

return pinView;
}
1

There are 1 answers

1
incanus On BEST ANSWER

Your populateAllLocation is triggering display of the annotation views, but the delegate method itself calls populateAllLocation so you have a loop. You should only be returning annotation views in the delegate, not altering the map.