我正在尝试在地图视图上放置多个引脚,但会出现错误

for (int i = 0; i < self.businessArray.count; i++) { Business *business = [self.businessArray objectAtIndex:i]; MapAnnotation *mapAnnotation = [[MapAnnotation alloc] init]; NSLog(@"%f %f", business.coordinate.latitude, business.coordinate.longitude); mapAnnotation.title = business.name; mapAnnotation.subtitle = business.address1; mapAnnotation.coordinate = business.coordinate; [bMapView addAnnotation:mapAnnotation]; NSLog(@"ti %@", mapAnnotation.title); NSLog(@"sub %@", mapAnnotation.subtitle); NSLog(@"coo %f %f", mapAnnotation.coordinate.latitude, mapAnnotation.coordinate.longitude); } - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { MKPinAnnotationView *pinView; if (annotation != mapView.userLocation) { static NSString *defauleID = @"myLocation"; // pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:defauleID]; if (pinView == nil) { pinView = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier:defauleID]; } pinView.pinColor = MKPinAnnotationColorGreen; pinView.canShowCallout = YES; pinView.animatesDrop = YES; UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; [rightButton setTitle:annotation.title forState:UIControlStateNormal]; [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside]; pinView.rightCalloutAccessoryView = rightButton; } return pinView; } 

错误:MapAnnotation类的实例0x1cdd97b0被释放,而键值观察者仍然在其中注册。 观测信息被泄露,甚至可能被误认为是其他物体。 在NSKVODeallocateBreak上设置断点,在debugging器中停止。 以下是当前的观察信息:(上下文:0x0,属性:0x1cd97a30>

每次在循环内释放注释

  for (int i = 0; i < self.businessArray.count; i++) { Business *business = [self.businessArray objectAtIndex:i]; MapAnnotation *mapAnnotation = [[MapAnnotation alloc] init]; NSLog(@"%f %f", business.coordinate.latitude, business.coordinate.longitude); mapAnnotation.title = business.name; mapAnnotation.subtitle = business.address1; mapAnnotation.coordinate = business.coordinate; NSLog(@"ti %@", mapAnnotation.title); NSLog(@"sub %@", mapAnnotation.subtitle); NSLog(@"coo %f %f", mapAnnotation.coordinate.latitude, mapAnnotation.coordinate.longitude); [bMapView addAnnotation:mapAnnotation]; [mapAnnotation release]; } 

我认为你已经收到通知添加观察员..当你收到通知,并执行与该观察员相关的function释放你的MapAnnotation但你不删除该观察员,请删除旁观者也dealloc …

  [[NSNotificationCenter defaultSenter] removeObserver:self]; 

希望对你有帮助..