SDWebImage - 来自 url 的图像在完成下载后未替换占位符图像

SDWebImage - Image from url didn't replace placeholder image after it's finished download

我正在使用 SDWebImage 在 UIImageView 中异步下载和缓存图像,但我遇到了一些问题。

在我的项目中,我创建了一个图钉标记,它有一个对话框,里面有 UIImageView。

我面临的问题是来自 url 的图像在完成下载后没有替换占位符图像。第一次单击图钉标记将始终显示占位符图像。

来自url的图片只有在我第二次点击图钉标记后才会显示。

我想在第一次点击时显示来自 url 的图像,我应该怎么做?

这是我的代码

    -(UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
PlaceData *currentMarker = [self findDataByMarker:marker];

UIView *dialogView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 261, 95)];

// Create background image
UIImageView *dialogBackground = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"MapDialog.png"]];
[dialogView addSubview:dialogBackground];

UIImageView * thumbnail = [[UIImageView alloc] init];

[thumbnail sd_setImageWithURL:[NSURL URLWithString:currentMarker.thumbnail] placeholderImage:[UIImage imageNamed:@"placeholder.png"] options:SDWebImageRefreshCached];

NSLog(@"URL %@", currentMarker.thumbnail);
NSLog(@"thumbnail %@",thumbnail);



CGRect tmpFrame = thumbnail.frame;
tmpFrame.origin.x = 15;
tmpFrame.origin.y = 14;
tmpFrame.size.width = 55;
tmpFrame.size.height = 55;
thumbnail.frame = tmpFrame;
thumbnail.contentMode = UIViewContentModeScaleToFill;
[dialogView addSubview:thumbnail];

return dialogView;

PS。请帮我解决这个问题,对不起我的英语。

请尝试使用此代码

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    [thumbnail sd_setImageWithURL:[NSURL URLWithString:currentMarker.thumbnail] placeholderImage:[UIImage imageNamed:@"placeholder.png"] options:SDWebImageRefreshCached];
});

[.retryFailed, .refreshCached] 帮助解决了我的问题。

imageView.sd_setImage(with: picnicThumbnail, maxImageSize: 100000, placeholderImage: placeholderImage, options: [.retryFailed, .refreshCached], completion : nil)