加载图像的SDWebImage错误

时间:2015-06-05 06:14:10

标签: ios objective-c xcode6 sdwebimage

当我尝试使用SDWebImage加载图像时,它显示的错误如

  

< 'UIImage'没有可见的@interface声明选择器'sd_setImageWithURL:placeholderImage:'>

我正在尝试在tableview单元格的imageview中加载图像,如下所示:

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

4 个答案:

答案 0 :(得分:2)

更改

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

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

答案 1 :(得分:0)

如果newsImageUIImageView,则代码应如下所示。

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

- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)占位符

上述方法适用于UIImageView,您将此方法应用于UIimage,因此可能会崩溃。

答案 2 :(得分:0)

imageView 上应用此方法,而不是在 imageView.image

使用此代码:

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

也不要忘记导入

#import <SDWebImage/UIImageView+WebCache.h>

答案 3 :(得分:0)

请尝试使用以下代码 -

添加您的viewcontroler - #import <SDWebImage/UIImageView+WebCache.h>

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