SDWebImage始终加载占位符图像而不是URL中的图像

时间:2012-11-17 21:38:10

标签: iphone objective-c ios uiimageview sdwebimage

使用SDWeb图像Here

和我的代码:

        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加载图像,但它不会改变占位符图像。

这些是我的问题的屏幕。

enter image description here

3 个答案:

答案 0 :(得分:3)

也尝试以下

[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");
        }];

答案 1 :(得分:1)

尝试以下

UIImageView *sellerImage = [[UIImageView alloc]init];            
[sellerImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:
[productPicture stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

答案 2 :(得分:0)

正确分配占位符图像..问题是我的图像扩展名错误,彼此不匹配,即placeholder.jpeg和palceholder@2x.jpg

相关问题