SDWebImage error for loading image

2k views Asked by At

When I am trying to load image using SDWebImage,it's showing error like

< No visible @interface for 'UIImage' declares the selector 'sd_setImageWithURL:placeholderImage:'>

I am trying to load the image in a imageview in tableview cell like this:

[newsImage.image sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row] objectForKey:@"image"]]
                      placeholderImage:[UIImage imageNamed:@"tab.png"]];
4

There are 4 answers

0
Fawad Masud On

Change

[newsImage.image sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row] objectForKey:@"image"]]
                  placeholderImage:[UIImage imageNamed:@"tab.png"]];

To

[newsImage sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row] objectForKey:@"image"]]
                  placeholderImage:[UIImage imageNamed:@"tab.png"]];
0
Rahul Patel On

If newsImage is your UIImageView then code should be as below.

[newsImage sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row] objectForKey:@"image"]]
                  placeholderImage:[UIImage imageNamed:@"tab.png"]];

-(void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder

Above method is for UIImageView and you were applying this method to UIimage so it might crashing.

0
Utsav Parikh On

Apply this method on imageView, and not on imageView.image

Use this code :

[newsImage sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row] objectForKey:@"image"]] placeholderImage:[UIImage imageNamed:@"tab.png"]];

Also don't forget to import

#import <SDWebImage/UIImageView+WebCache.h>
0
Santu C On

Please try with below code -

Add in your viewcontroler - #import <SDWebImage/UIImageView+WebCache.h>

[newsImage  sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row]
                 placeholderImage:[UIImage imageNamed:@"tab.png"]
                          options:SDWebImageRefreshCached];