使用SDWebImage在UITableViewCell中加载图片,首屏加载失败如何解决?

2026-06-09 04:434阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计172个文字,预计阅读时间需要1分钟。

使用SDWebImage在UITableViewCell中加载图片,首屏加载失败如何解决?

swift// 修改后的代码tableView(tableView: tableView, cellForRowAtIndexPath: NSIndexPath(forRow: 0, inSection: 0))

1234567891011121314151617181920 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAt

1234567891011121314151617181920 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];         cell.textLabel.text = @"标题";        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"static.open-open.com/j300250n.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {                NSData *fData = UIImageJPEGRepresentation(image, 1.0);                NSLog(@"和火凤凰%@   %d", cell.imageView.image, fData.length);                   }];          return cell;  }

如代码。就是加载远程图片。问题就是。页面第一次加载的时候cell里面的图片没有显示。而再执行一次reload之后,图片就显示了。如何解决?以及产生的原因?

另外,我如果使用一张本地图片,则没有这个问题

   

使用SDWebImage在UITableViewCell中加载图片,首屏加载失败如何解决?

本文共计172个文字,预计阅读时间需要1分钟。

使用SDWebImage在UITableViewCell中加载图片,首屏加载失败如何解决?

swift// 修改后的代码tableView(tableView: tableView, cellForRowAtIndexPath: NSIndexPath(forRow: 0, inSection: 0))

1234567891011121314151617181920 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAt

1234567891011121314151617181920 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];         cell.textLabel.text = @"标题";        [cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"static.open-open.com/j300250n.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {                NSData *fData = UIImageJPEGRepresentation(image, 1.0);                NSLog(@"和火凤凰%@   %d", cell.imageView.image, fData.length);                   }];          return cell;  }

如代码。就是加载远程图片。问题就是。页面第一次加载的时候cell里面的图片没有显示。而再执行一次reload之后,图片就显示了。如何解决?以及产生的原因?

另外,我如果使用一张本地图片,则没有这个问题

   

使用SDWebImage在UITableViewCell中加载图片,首屏加载失败如何解决?