【问题标题】:UITableView loading images after app loads应用程序加载后 UITableView 加载图像
【发布时间】:2012-01-17 04:33:43
【问题描述】:

所以我正在编写一个应用程序,它会从网站 URL 中获取专辑封面。

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

然后将数组加载到 UITableView 中。

这很好用...除了加载应用程序需要 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;

}

非常感谢!

【问题讨论】:

    标签: iphone ios cocoa-touch uitableview uikit


    【解决方案1】:

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

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

    它包括如何使用它的示例

    【讨论】:

      【解决方案2】:

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

      如需全套相关代码,请查看SDWebImage

      或者对于异步视图代码,请查看this link

      【讨论】:

        【解决方案3】:

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

        https://github.com/AFNetworking/AFNetworking

        【讨论】:

          猜你喜欢
          • 2017-03-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-05
          • 2019-09-25
          相关资源
          最近更新 更多