首先在MKMapView中只有用戶位置。一些行動後,我打電話方法: [self mapView:self.mapView didAddAnnotationViews:self.pointersArray];
我didAddAnnotationViews
方法:MKMapView應用程序在使用縮放後崩潰
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
if (views.count == 1) {
MKAnnotationView *annotationView = [views objectAtIndex:0];
id<MKAnnotation>mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 500, 500);
[mapView setRegion:region animated:YES];
}
else {
[mapView addAnnotations:views];
}
}
應用程序沒有崩潰,直到不使用變焦。但是當縮放使用超過10次(約)時,我在這個[mapView addAnnotations:views];
或有時在return UIApplicationMain(argc, argv, nil, NSStringFromClass([BIDAppDelegate class]));
中出錯。錯誤 - EXC_BAD_ACCESS
。有我的問題?
編輯
更改爲[self.mapView setRegion:region animated:YES];
但現在我在主線程MKNormalizedPointForLayer EXC_BAD_ACCESS
錯誤。在通常的變焦工作,使用變焦例如7次以上的應用程序崩潰.. 我的按鈕的動作:
- (void)showKantorsOnMap {
if (self.kantorsData.count != self.pointersArray.count) {
NSLog(@"need to wait more");
}
NSMutableArray *toRemove = [[NSMutableArray alloc] init];
for (id annotation in self.mapView.annotations)
if (annotation != self.mapView.userLocation)
[toRemove addObject:annotation];
[self.mapView removeAnnotations:toRemove];
[self.mapView addAnnotations:self.pointersArray];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.mapView.userLocation.coordinate,6500, 6500);
[self.mapView setRegion:region animated:YES];
}
SOLUTION 問題是didAddAnnotationViews
方法[mapView addAnnotations:views];
稱爲遞歸。
你會說俄語嗎?) – RomanHouse 2012-07-09 15:16:12
不,不幸的不是。 – Anna 2012-07-09 15:29:01
對不起,基於您的暱稱:)。我編輯了我的問題。也許需要另一個我的代碼? – RomanHouse 2012-07-09 15:37:03