Search code examples
iosiphoneios6ios7sdwebimage

How to use success & failure block in SDwebimage


I have latest version of SDWebimage but it doesnt have Success & failure I tried the following method but SDwebimage doesnt have method

[self.imageView setImageWithURL:[NSURL URLWithString:self.imageURL]
              placeholderImage:[UIImage imageNamed:@"YourPlaceholder.png"]
                       success:^(UIImage *image) {
                           // remove animation

                       }
                       failure:^(NSError *error) {
                           NSLog(@"thumbnail error: %@",error);
                           // handle failed download

                       }];

Does anybody know how to add success & failure block in SDwebimage setImageWithURL or any other alternatife I want to handle if there is some error while getting image from URL


Solution

  • Try this:

    [self.imageView setImageWithURL:[NSURL URLWithString:imageURL]
                       placeholderImage:[UIImage imageNamed:@"YourPlaceholder.png"]
                              completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
                                  //... completion code here ...
                              }];