【问题标题】: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 &lt;SDWebImage/UIImageView+WebCache.h&gt;

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-04-15
          • 1970-01-01
          • 2015-05-06
          • 1970-01-01
          • 1970-01-01
          • 2013-08-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多