【问题标题】:SDWebImage error for loading image加载图像的 SDWebImage 错误
【发布时间】:2015-06-05 14:24:33
【问题描述】:
当我尝试使用 SDWebImage 加载图像时,它会显示类似的错误
我正在尝试将图像加载到 tableview 单元格中的 imageview 中,如下所示:
[newsImage.image sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row] objectForKey:@"image"]]
placeholderImage:[UIImage imageNamed:@"tab.png"]];
【问题讨论】:
标签:
ios
objective-c
xcode6
sdwebimage
【解决方案1】:
改变
[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"]];
【解决方案2】:
如果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,因此它可能会崩溃。
【解决方案3】:
将此方法应用于 imageView,而不是 imageView.image
使用此代码:
[newsImage sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row] objectForKey:@"image"]] placeholderImage:[UIImage imageNamed:@"tab.png"]];
别忘了导入
#import <SDWebImage/UIImageView+WebCache.h>
【解决方案4】:
请尝试以下代码 -
添加您的视图控制器 - #import <SDWebImage/UIImageView+WebCache.h>
[newsImage sd_setImageWithURL:[NSURL URLWithString:[jsonResult[indexPath.row]
placeholderImage:[UIImage imageNamed:@"tab.png"]
options:SDWebImageRefreshCached];