2
我想從一個URL添加圖像到。我正在使用線程來加載圖像。我將MKAnnotationView對象傳遞給另一個方法並在該方法中加載圖像。當我點擊註釋第一次圖像加載,但沒有顯示註釋,但當我再次點擊第二次顯示。我無法找到錯誤。MKAnnotationn leftcalloutaccessoryview沒有得到刷新
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
NSLog(@"Selected View Tag = %d", view.tag);
UIImageView *imaged = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,31,31)];
act = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0,0,31,31)];
[act startAnimating];
[imaged addSubview:act];
view.leftCalloutAccessoryView = imaged;
[NSThread detachNewThreadSelector:@selector(threadaimage:) toTarget:self withObject:view];
}
-(void)threadaimage:(MKAnnotationView*)imageview1
{
NSLog(@"Selected Tag in Thread Method = %d",imageview1.tag);
UIButton *imag = [[UIButton alloc]init];
imag.frame = CGRectMake(0, 0, 31, 31);
NSData *imageData = [NSData dataWithContentsOfURL:
[NSURL URLWithString:[image_arr objectAtIndex:imageview1.tag]]];
NSLog(@"%@",[image_arr objectAtIndex:imageview1.tag]);
[imag setImage:[UIImage imageWithData:imageData] forState:UIControlStateNormal];
[self.view addSubview:imag];
imageview1.leftCalloutAccessoryView = imag;
[act stopAnimating];
}