简体   繁体   English

TableCell ImageView设置带有URL的图像:SDWebImage:仅调整第一行的大小

[英]TableCell ImageView Set Image With URL: SDWebImage: Only resizing first row

Inside my method I have the following code. 在我的方法中,我有以下代码。

It works great on the fist table row record, however the remaining cells don't get resized. 它在第一个表格行记录上的效果很好,但是其余单元格不会调整大小。

HOWEVER , when I start scrolling, they do. 但是 ,当我开始滚动时,它们会滚动。 I can't seem to figure out why. 我似乎不知道为什么。 Is there something more I need to be doing? 还有什么我需要做的吗?

[cell.imageView sd_setImageWithURL:url
                  placeholderImage: [UIImage imageNamed:@"default.png"]
                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

                          if (image) {

                              NSLog(@"%@", account);

                              CGSize itemSize = CGSizeMake(32, 32);
                              UIGraphicsBeginImageContext(itemSize);
                              CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
                              [image drawInRect:imageRect];
                              cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
                              UIGraphicsEndImageContext();
                              cell.imageView.layer.cornerRadius = 16;
                              cell.imageView.clipsToBounds = YES;
                          }
    }];

I had the same problem. 我有同样的问题。 The completed block of SDWebImage does not run on the UI thread and hence ui updates do not make it to the screen. SDWebImage的已完成块不会在UI线程上运行,因此ui更新不会显示在屏幕上。

Adding the following in the completion block solved it for me: 在完成块中添加以下内容为我解决了问题:

dispatch_async(dispatch_get_main_queue(), ^{
  [cell setNeedsLayout];
});

Eg it is necessary to dispatch a request for relayout of the cell to the ui thread. 例如,有必要向ui线程分派将单元重传的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM