[英]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.