我正在做一个教程,他们要求我在后台将 urlimage 加载到 uitableview。下面是我正在使用的代码,它的加载速度非常慢。有没有让它加载更快的代码?
NSOperationQueue* backgroundQue =[[ NSOperationQueue alloc]init];
int websiteNumber=0;
for (NSString* website in websites){
[backgroundQue addOperationWithBlock:^{
NSURL* iconURL=[NSURL URLWithString:
[NSString stringWithFormat:@"http://%@/favicon.ico", website]];
NSURLRequest*request=[NSURLRequest requestWithURL:iconURL];
NSData* loadData = [NSURLConnection
sendSynchronousRequest:request returningResponse:nil error:nil];
if(loadData !=nil){
UIImage* loadImage= [UIImage imageWithData:loadData];
if(loadImage ==nil){
return ;
}
[[NSOperationQueue mainQueue]addOperationWithBlock:^{
[websiteIcons replaceObjectAtIndex:websiteNumber withObject:loadImage];
[self.tableView reloadData];
}];
}
}];
websiteNumber++;
}