【发布时间】:2011-08-12 19:44:52
【问题描述】:
我有一个 MKMapview 加载可能有 5 个注释(现在)。它加载得很好,还有注释。每个注释都包含正确的左右标注。但是过了一段时间(可能是 2 分钟),我经常在注释的左侧标注处遇到 EXC_BAD_ACCESS 崩溃...
- (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];
}
我在想也许我的应用仍在尝试加载注释,但我不知道为什么。同样,在加载地图时我会收到一些内存警告,所以也许我没有按照我应该的方式释放一些对象,我对内存管理的工作方式还是有点陌生,所以任何建议都会有所帮助。
【问题讨论】:
标签: objective-c mkmapview mkannotation mkannotationview