簡體   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