gpt4 book ai didi

iphone - MKAnnotationn leftcalloutaccessoryview 没有得到刷新

转载 作者:行者123 更新时间:2023-11-29 13:43:58 24 4
gpt4 key购买 nike

我正在尝试从 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];
}

最佳答案

好吧,我想我终于为你弄明白了:)

我所做的是 - 我创建了一个按钮,将 activityIndi​​cator 作为 subview 添加到它,当有图像下载时,我将图像设置到同一个按钮。并删除事件指示器。在我身边工作。这是我最终得到的代码:

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
UIButton *customAccessoryButton = [UIButton buttonWithType:UIButtonTypeCustom];

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


act = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0,0,31,31)];

[act startAnimating];

[customAccessoryButton addSubview:act];

view.leftCalloutAccessoryView = customAccessoryButton;

[NSThread detachNewThreadSelector:@selector(threadaimage:) toTarget:self withObject:view];
}


- (void)threadaimage:(MKAnnotationView*)imageview1
{
UIButton *customAccessoryButton = (UIButton*)imageview1.leftCalloutAccessoryView;

NSData *imageData = [NSData dataWithContentsOfURL:
[NSURL URLWithString:@"http://www.gemini.edu/images/stories/press_release/pr2008-6/fig1.jpg"]];

[customAccessoryButton setImage:[UIImage imageWithData:imageData] forState:UIControlStateNormal];

[act removeFromSuperview];

[act stopAnimating];
}

关于iphone - MKAnnotationn leftcalloutaccessoryview 没有得到刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8214860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com