2011-08-12 3 views
0

어쩌면 5 개의 주석 (현재)이있는 MKMapview가로드되어 있습니다. 주석은 잘로드됩니다. 각 주석은 올바른 왼쪽 및 오른쪽 설명 선을 포함합니다. 그러나 잠시 후에 (아마 2 분) 나는 종종 내가 어쩌면 내 응용 프로그램은 여전히 ​​주석을로드하려고 생각하고있다} ... 주석의 왼쪽 선에,iphone mkannotation :지도가로드 된 후 왼쪽 설명 선의 경고

- (MKAnnotationView *) mapView:(MKMapView *)thisMapView 
     viewForAnnotation:(MapAnnotations *)annotation 
{ 
static NSString *MapIdentifier = @"MapIdentifier"; 

UIImageView *myImageView; 
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[thisMapView dequeueReusableAnnotationViewWithIdentifier:MapIdentifier]; 

if(annotationView == nil) 
{ 
    NSString * id = [NSString stringWithFormat:@"%d", (annotation).tag]; 
    NSString * postPhoto = [NSString stringWithFormat:@"id=%@",id]; 
    NSString * hostStrPhoto = @"http://domain.com/get_image.php?"; 
    hostStrPhoto = [hostStrPhoto stringByAppendingString:postPhoto]; 

    NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:hostStrPhoto]]; 

    myImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: imgData]]; 

    myImageView.frame = CGRectMake(0,0,31,31); 

    annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:MapIdentifier] autorelease]; 

} 

annotationView.animatesDrop=TRUE; 


annotationView.canShowCallout = YES; 
annotationView.leftCalloutAccessoryView = myImageView; //<--where I am getting the error, after all the annotations have loaded. 
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 

return annotationView; 

[myImageView autorelease]; 

을 EXC_BAD_ACCESS 충돌을 얻을 , 그러나 나는 이유를 이해할 수 없다. 지도가로드 될 때 일부 메모리 경고가 발생하므로, 내가해야하는 방식으로 일부 객체를 릴리스하지 않을 것입니다. 메모리 관리가 작동하는 방식에 대해 여전히 새로운 것이므로 어떤 제안이라도 도움이 될 것입니다.

답변

1

주석보기를 다시 사용하게되면 myImageView가 생성되지 않고 해제됩니다. myImageView를 맨 위에 nil로 설정하십시오.

- (MKAnnotationView *) mapView:(MKMapView *)thisMapView viewForAnnotation:(MapAnnotations *)annotation { 
    static NSString *MapIdentifier = @"MapIdentifier"; 

    UIImageView *myImageView = nil; 
    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[thisMapView dequeueReusableAnnotationViewWithIdentifier:MapIdentifier]; 

    if(annotationView == nil) { 
     NSString * id = [NSString stringWithFormat:@"%d", (annotation).tag]; 
     NSString * postPhoto = [NSString stringWithFormat:@"id=%@",id]; 
     NSString * hostStrPhoto = @"http://domain.com/get_image.php?"; 
     hostStrPhoto = [hostStrPhoto stringByAppendingString:postPhoto]; 

     NSData *imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:hostStrPhoto]]; 

     myImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: imgData]]; 

     myImageView.frame = CGRectMake(0,0,31,31); 

     annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:MapIdentifier] autorelease]; 
    } 

    annotationView.animatesDrop=TRUE; 
    annotationView.canShowCallout = YES; 
    annotationView.leftCalloutAccessoryView = myImageView; //<--where I am getting the  error, after all the annotations have loaded. 
    annotationView.rightCalloutAccessoryView = [UIButton  buttonWithType:UIButtonTypeDetailDisclosure]; 

    return annotationView; 

    [myImageView release]; 
} 
+0

지금은 상당히 잘 작동합니다. 지금까지 충돌 없음 :) – amanda

관련 문제