为什么使用SDWebImage加载图片时,第一次点击单元格无法显示图片?
- 内容介绍
- 文章标签
- 相关推荐
本文共计172个文字,预计阅读时间需要1分钟。
objective-c// 简化代码如下:- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // ...}
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之后,图片就显示了。如何解决?以及产生的原因?
另外,我如果使用一张本地图片,则没有这个问题
本文共计172个文字,预计阅读时间需要1分钟。
objective-c// 简化代码如下:- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // ...}
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之后,图片就显示了。如何解决?以及产生的原因?
另外,我如果使用一张本地图片,则没有这个问题

