gpt4 book ai didi

ios - 来自 url 的按钮的图像 - 等待 10 秒后返回失败。主运行循环模式 : kCFRunLoopDefaultMode

转载 作者:行者123 更新时间:2023-12-01 16:36:47 24 4
gpt4 key购买 nike

我有一个包含 json 格式的 URL。

{
"name":"RAI Radiodue",
"cat":"Adult Contemporary",
"img":"http://www.rai.it/dl/portaleRadio/images/ico_radio2.jpg",
"url":"http://www.listenlive.eu/rai2.m3u"
},
{
"name":"RAI Radiotre",
"cat":"Classical/Culture",
"img":"http://www.rai.it/dl/portaleRadio/images/ico_radio3.jpg",
"url":"http://www.listenlive.eu/rai3.m3u"
}........etc

我正在尝试使用以下代码显示许多单选按钮:
    for (int i = 0;  i<[namesArray count]; i++) {

NSURL *url = [NSURL URLWithString: [pictureUrl objectAtIndex:i]];

NSData *data = [NSData dataWithContentsOfURL:url];
UIImageView *subview = [[UIImageView alloc] init];
[subview setImage:[UIImage imageWithData:data]];



UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];

int xxx = i%3;
int yyy = i/3.0f;
[bt setFrame:CGRectMake(35+95*xxx, 15+100*yyy, 60, 60)];
[bt setBackgroundImage:subview forState:UIControlStateNormal];

bt.tag = 200+i;
bt.selected = NO;
[bt.layer setMasksToBounds:NO];
[bt.layer setShadowColor:[UIColor blackColor].CGColor];
[bt.layer setShadowOpacity:0.8f];
[bt.layer setShadowOffset:CGSizeMake(1.0f, 1.0f)];
[bt addTarget:self action:@selector(Play:) forControlEvents:UIControlEventTouchUpInside];
[mainscroll addSubview:bt];
}

并为每个按钮添加来自 pictureUrl 的已填充图像,但是当我想转到此 View Controller 时,我在控制台中得到此输出:
2014-12-18 17:32:40.763 TV[3128:935103] NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
2014-12-18 17:32:46.041 TV[3128:935134] void SendDelegateMessage(NSInvocation *): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode.

我该怎么办 ?

最佳答案

NSData *data = [NSData dataWithContentsOfURL:url]; 

此行阻塞主线程,主线程在运行此行之前会等待数据下载:
UIImageView *subview = [[UIImageView alloc] init];
[subview setImage:[UIImage imageWithData:data]];

您必须在其他线程中运行下载数据并在下载数据时设置您的图像。

关于ios - 来自 url 的按钮的图像 - 等待 10 秒后返回失败。主运行循环模式 : kCFRunLoopDefaultMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27550246/

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