简体   繁体   English

SDWebImage加载图像错误

[英]SDWebImage error for loading image

When I am trying to load image using SDWebImage,it's showing error like 当我尝试使用SDWebImage加载图像时,显示如下错误

< No visible @interface for 'UIImage' declares the selector 'sd_setImageWithURL:placeholderImage:'> <'UIImage'的无可见@interface声明选择器'sd_setImageWithURL:placeholderImage:'>

I am trying to load the image in a imageview in tableview cell like this: 我试图像这样在tableview单元中的imageview中加载图像:

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

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"]];

If newsImage is your UIImageView then code should be as below. 如果newsImage是您的UIImageView则代码应如下所示。

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

-(void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder -(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. 上面的方法是针对UIImageView ,您将此方法应用于UIimage因此可能会崩溃。

Apply this method on imageView , and not on imageView.image imageView而不是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>

Please try with below code - 请尝试以下代码-

Add in your viewcontroler - #import <SDWebImage/UIImageView+WebCache.h> 在您的ViewController中添加- #import <SDWebImage/UIImageView+WebCache.h>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM