【问题标题】:Reloading UITableView while downloading images via afnetworking通过afnetworking下载图像时重新加载UITableView
【发布时间】:2013-06-20 00:05:20
【问题描述】:

在我的 cellForRowAtIndexPath 方法中,我有一些代码可以通过 UIImageView+AFNetworking 类别异步下载图像 但据我所知,每次我将表格滚动到单元格时,以及每次开始图像下载时都会调用 cellForRowAtIndexPath 方法。我可以缓存图像或单元格或类似的东西吗?

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //some code here
    [imageView setImageWithURL: myURL placeholderImage:[UIImage imageNamed:@"placeholder"]];
    //some other code here
    return cell;
}

【问题讨论】:

  • 不是 [imageView setImageWithURL: myURL placeholderImage:[UIImage imageNamed:@"placeholder"]];
  • 但是 [cell.imageView setImageWithURL: myURL placeholderImage:[UIImage imageNamed:@"placeholder"]];
  • 您可以使用edit 链接更正您发布的代码。

标签: uitableview uiimage afnetworking


【解决方案1】:

UIImageView+AFNetworking 将使用AFImageCacheNSCache 子类)自动缓存您的图像,因此它们不需要下载两次。

当单元格滚动回视图时,只要 URL 相同,它将使用缓存的图像而不是进行网络调用。

如果您经常使用该类别的实现源代码,可能会对您有所帮助。 source code can be found here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多