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

Answers


Try this:

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

Solution for Swift 3 :

cell.imageView?.sd_setImage(with: url) { (image, error, cache, urls) in
            if (error != nil) {
                //Failure code here
                cell.imageView.image = UIImage(named: "ico_placeholder")
            } else {
                //Success code here
                cell.imageView.image = image
            }
}

Solution for Objective C :

[cell.imageView sd_setImageWithURL:url
                  placeholderImage:nil
                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                                if (error) {
                                  //Failure code here
                                  self.imageView.image = [UIImage imageNamed:@"ico_placeholder"];
                                } else {
                                  //Success code here
                                  self.imageView.image = image;
                                }
}];

Hope you guys find this useful.


            imageView.sd_setImageWithURL(NSURL(string: urlString), completed: {
                (image, error, cacheType, url) in
                // do your custom logic here
            })

sample code for swift 2.0


it has completion block

completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)

You can check if error is nil, then everything is fine.


Need Your Help

Changing padding based on form input

jquery css

I am trying (it's not working) to pad an element based on a form input. If the input is more than one integer it should change the padding. This is my script right now.

Gauges for Compact Framework Applications

compact-framework dashboard gauge

Can anybody recommend gauge components for Compact Framework applications?