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

时间:2012-01-17 04:33:43

标签: iphone ios cocoa-touch uitableview uikit

所以我正在编写一个应用程序,它从网站网址中提取专辑图片。

基本上我到目前为止编写的是读入的文件,其中包含专辑图片的URL。然后使用文件中的数据构造二维NSMutableArray,并从文件中的各个URL初始化UIImages,然后将其存储在数组中。

然后将数组加载到UITableView。

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

加载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;

}

非常感谢!

3 个答案:

答案 0 :(得分:0)

最有可能的原因是因为您的图像检索阻塞了主线程。 使用它来管理异步加载的图像。

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

它包括如何使用它的样本

答案 1 :(得分:0)

您真正想要做的是在后台线程中加载图像。

如需完整的相关代码套件,请查看SDWebImage

或者仅针对异步视图代码,结帐this link

答案 2 :(得分:0)

AFNetworking非常适合异步加载,甚至还带有处理图像加载的功能(例如,Album Artwork)。 github repo包含示例代码。

https://github.com/AFNetworking/AFNetworking