繁体   English   中英

SDWebImage加载图像错误

[英]SDWebImage error for loading image

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

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

我试图像这样在tableview单元中的imageview中加载图像:

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

更改

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

如果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

上面的方法是针对UIImageView ,您将此方法应用于UIimage因此可能会崩溃。

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

使用此代码:

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

也别忘了导入

#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