![](/img/trans.png)
[英]How know whether image is coming from cache or form url in SDWebImage?
[英]SDWebImage always load the placeholder image not the image from URL
嗯在這里使用SDWeb圖像
這些我的代碼:
UIImageView *sellerImage = [[UIImageView alloc]init];
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:productPicture]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
但它總是加載占位符圖像不僅沒有從URL的形象,我試圖用塊,以確保如果它加載的圖像或不和它進入到成功阻止這意味着SDWebImage可以從URL加載圖像,但它不會更改占位符圖像。
這些是代碼當我嘗試使用塊時:
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:productPicture]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
success:^(UIImage *image, BOOL cached)
{
NSLog(@"success Block");
}
failure:^(NSError *error)
{
NSLog(@"failure Block");
}];
正如我所說,它總是在成功阻止,這意味着它可以從URL加載圖像,但它不會改變占位符圖像。
這些是我的問題的屏幕。
也嘗試以下
[sellerImage setImageWithURL:[NSURL URLWithString:[productPicture stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
success:^(UIImage *image, BOOL cached)
{
dispatch_async(dispatch_get_main_queue(), ^{
sellerImage.image = image;
});
NSLog(@"success Block");
}
failure:^(NSError *error)
{
NSLog(@"failure Block");
}];
嘗試以下方法
UIImageView *sellerImage = [[UIImageView alloc]init];
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:
[productPicture stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
正確分配占位符圖像..問題是我的圖像擴展名錯誤,彼此不匹配,即placeholder.jpeg和palceholder@2x.jpg
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.