MKAnnotationn leftcalloutaccessoryview 未刷新
我正在尝试从 URL 添加图像。我正在使用线程来加载图像。我将 MKAnnotationView 对象传递给另一个方法并在该方法中加载图像。当我第一次单击注释时,图像正在加载但未显示在注释上,但当我再次单击第二次时,它会显示。我无法找到错误是什么。
-(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];
}
I am trying to add an image from a URL to. I am using a Thread to load image. i am passing MKAnnotationView object to another method and loading image in that method. When i click on the annotation first time image is loading but not showing on the annotation but when i click again on second time it is showing. I am unable to find what is the error.
-(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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想我终于为你弄清楚了:)
我所做的是 - 我创建了一个按钮,将 ActivityIndicator 添加到其中作为子视图,当下载图像时,我将图像设置为同一个按钮。并删除活动指示器。在我这边工作。这是我最终得到的代码:
Ok, I think I finally figured it out for You :)
What I did was - I created a button, add to it activityIndicator as a subview, and when there is image downloaded, I set up the image to the same button. And remove activity indicator. Works on my side. Here is code I ended up with: