SDWebImage always load the placeholder image not the image from URL

Abo3atef picture Abo3atef · Nov 17, 2012 · Viewed 8.5k times · Source

Um using the SDWeb image Here

and these my Code :

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

but it always load the placeholder image only not the image from URL, I've tried to use blocks to make sure if it load's the image or not and it enter to the Success Block which means that SDWebImage can load the image from URL but it doesn't change the place holder image.

These is the code When I tried to use blocks :

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

As I said it always goes in the success Block which means it can load the image from URL but it doesn't change the place holder image.

and these is a screen from my problem.

enter image description here

Answer

Ahmed picture Ahmed · Nov 17, 2012

also try the following

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