UITableView在应用程序加载后加载图像

问题描述:

因此,我正在编写一个应用程序,并从网站网址获取专辑图稿。UITableView在应用程序加载后加载图像

基本上我迄今写的是如何读入一个文件,其中包含专辑封面的URL。然后,使用文件中的数据构建二维NSMutableArray,并从文件中的单个URL初始化UIImages,然后将其存储在数组中。

然后将该数组加载到UITableView中。

这很好用...除了它需要像加载应用程序(lol)10秒钟。

那么一旦加载UITableView,有什么方法来加载图像?

这是我的cellForRowAtIndexPath方法,如果有帮助。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"]; 

if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"identifier"]autorelease]; 
} 

((UILabel *)[cell viewWithTag:artistTag]).text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:artistIndex]; 

((UILabel *)[cell viewWithTag:albumTag]).text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:albumIndex]; 

((UILabel *)[cell viewWithTag:dateTag]).text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:dateIndex]; 

((UIImageView *)[cell viewWithTag:imageTag]).image = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:imageIndex]; 

return cell; 

}

非常感谢!

最有可能的原因是因为您的图像检索阻止主线程。 用这个来管理异步加载的图像。

http://www.markj.net/hjcache-iphone-image-cache/

它包括如何使用它

你真正想要做的是加载图像在后台线程样本。

对于相关的代码全套,检查出SDWebImage

或者只是异步查看代码,结账this link

AFNetworking是异步加载非常好,甚至还带有功能用于处理图像加载(例如专辑封面)。 github回购包括示例代码。

https://github.com/AFNetworking/AFNetworking