블록 및 약한 참조와 관련된 문제가 발생했습니다. ARC를 사용하고 있습니다. Google Directions API를 둘러싼 간단한 래퍼 인 무료 프로젝트입니다. 여기에서 다운로드 할 수 있습니다. link to the project
보기 컨트롤러에서 사용하고 있습니다. 사용 후보기 컨트롤러가 문제가되지 않습니다. 할당이 취소되었습니다. 나는이 객체에 문제가 있다고 생각한다. 왜냐하면 내가 주석 처리하거나 nil로 설정하면 모든 것이 올바르게 동작하기 때문이다.블록 및 유지주기가 catch 할 수 없습니다.
- (void) getDirections{
__weak RouteMapViewController * weakSelf = self;
self.routeObject = [[RouteDirectionsObject alloc]init];
[self.mapView removeAnnotations:self.mapView.annotations];
[self.mapView removeOverlays:self.mapView.overlays];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[_routeObject createDirectionRequestWithStartPoint:weakSelf.startPoint
andEndPoint:weakSelf.endPoint
withCallBackBlock:^(NSError *error, NSDictionary *routeDistance, NSDictionary *routeDuration, MKPolyline *routePolyline, NSArray *routes, NSArray *steps, CLLocation *startPoint, CLLocation *endPoint, NSArray *directions) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
Annotation * startAnnotation = [[Annotation alloc]initWithCoordinate:startPoint.coordinate title:NSLocalizedString(@"YOUR_POSITION_KEY", @"Your position") annotationType:AnnotationTypeStart];
Annotation * endAnnotation = [[Annotation alloc]initWithCoordinate:endPoint.coordinate title:NSLocalizedString(@"AIRPORT_POSITION_KEY", @"Airport position") annotationType:AnnotationTypeEnd];
NSArray * annotationArray = [NSArray arrayWithObjects:startAnnotation, endAnnotation, nil];
weakSelf.routeSteps = steps;
weakSelf.routeDirections = directions;
weakSelf.duration = routeDuration;
weakSelf.distance = routeDistance;
CLLocationDegrees maxLat = -90.0f;
CLLocationDegrees maxLon = -180.0f;
CLLocationDegrees minLat = 90.0f;
CLLocationDegrees minLon = 180.0f;
for (int i = 0; i < weakSelf.routeSteps.count; i++) {
NSDictionary * stepDictCoordinate = [[weakSelf.routeSteps objectAtIndex: i]objectForKey:@"start_location"];
CLLocationCoordinate2D currentLocationCoordinate = CLLocationCoordinate2DMake([[stepDictCoordinate objectForKey:@"lat"]doubleValue], [[stepDictCoordinate objectForKey:@"lng"]doubleValue]);
if(currentLocationCoordinate.latitude > maxLat) {
maxLat = currentLocationCoordinate.latitude;
}
if(currentLocationCoordinate.latitude < minLat) {
minLat = currentLocationCoordinate.latitude;
}
if(currentLocationCoordinate.longitude > maxLon) {
maxLon = currentLocationCoordinate.longitude;
}
if(currentLocationCoordinate.longitude < minLon) {
minLon = currentLocationCoordinate.longitude;
}
}
MKCoordinateRegion region;
region.center.latitude = (maxLat + minLat)/2;
region.center.longitude = (maxLon + minLon)/2;
region.span.latitudeDelta = maxLat - minLat;
region.span.longitudeDelta = maxLon - minLon;
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error", @"Error alert view title") message:NSLocalizedString(@"KEY_DIRECTIONS_ERROR", @"Alert error message for directions") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[_routesButton setEnabled:NO];
}
else{
[weakSelf.mapView addAnnotations:annotationArray];
[_routesButton setEnabled:YES];
if(routePolyline){
[weakSelf.mapView addOverlay:routePolyline];
}
else{
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(@"Error", @"Error alert view title") message:NSLocalizedString(@"KEY_DIRECTIONS_POLYLINE_ERROR", @"Polyline inconsistant") delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
//[weakSelf.mapView setRegion:region animated:YES];
[weakSelf setRegion:region];
}
});
}];}
내가 넣으면 중단 점 및 뷰에 대한 질문 : 나는 약한 자기로 설정 물론, 유지 사이클입니다 이해할 수 아니에요, 여기에 내가 그것을 사용하는 뷰 컨트롤러의 방법입니다 컨트롤러의 retainCount보기 컨트롤러가 전달 된 경우에도 다른 시간이 증가하는 것을 볼 수 있습니다 약한. 도움이 될 것입니다.
감사합니다,
안드레아
/* ** * ** * ** * **UPDATE* ** * ** 을 * ** * */**
할당 확인 블록 내부에서 -tryRetain
이라는 메서드를 통과 할 때까지 뷰 컨트롤러가 계속 유지되는 것을 볼 수 있지만 할당 해제를 위해 하나의 릴리스가 누락 된 것처럼 보입니다. 전달 된 블록이 클래스 경로 방향 객체에 복사되도록 지정해야합니다. 여기에서 다운로드 할 수있는 작은 샘플을 만들었습니다. download project
는 또한 자기 클래스, 예를 들어 _routerButton의 (블록) 인스턴스 변수를 사용하지 말아야합니다 귀하의 경우 자체 클래스, _routerButton의 (블록) 인스턴스 변수를 사용할 수 없습니다. – NeverBe
OMG ... 여기서 두 개의 _routeButton 인스턴스에 주석 처리가되어 있습니다. 모든 인스턴스가 올바르게 할당 해제됩니다. 단일 인스턴스로 복사 된 것 같습니다. 내가 그것을 확인하는 대답으로 써주세요. 정말 고맙습니다. – Andrea