【问题标题】:SDWebImage not workingSDWebImage 不工作
【发布时间】:2014-08-12 00:53:31
【问题描述】:

我正在尝试使用 SDWebImage 从网络下载图像。但它不起作用。我该如何解决?

DetailView.m:

#import "DetailViewController.h"
#import "UIImageView+WebCache.h"

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.imageView sd_setImageWithURL: [NSURL URLWithString:_downloadedimage]
                   placeholderImage:[UIImage imageNamed:@"image.png"]];

    self.imageView.frame = (CGRect){.origin=CGPointMake(1.0f, 1.0f), .size=_img.size};  // I think what error here
    [self.scrollView addSubview:self.imageView];

    self.scrollView.contentSize = _img.size; // and here?
}

感谢您的帮助。

【问题讨论】:

  • 不工作?详细说明您的期望和得到的结果?
  • 这是一个关于 SWWebImage 的类似问题,如果您查看该答案可能会有所帮助stackoverflow.com/questions/24984949/…
  • ImageView 总是空的。
  • 您确认self.imageView 不是nil
  • 我在代码 if (_imageView.image==nil) {AlertView} 中写过,我得到的 ImageView 总是为零。

标签: ios objective-c sdwebimage


【解决方案1】:

首先导入库。

#import <SDWebImage/UIImageView+WebCache.h>

然后添加这一行

[self.imageView setImageWithURL:[NSURL URLWithString:@"urlString" placeholderImage:[UIImage imageNamed:@"abc.png"]];

确保您使用包含一些图片的有效网址,并且您分配给占位符的图片也应该在那里。

【讨论】:

  • 标记为正确的答案是相同的,所以为什么不赞成。
【解决方案2】:

看起来你没有初始化 imageview。试着在之前做。

- (void)viewDidLoad
{
    [super viewDidLoad];
    if (self.imageView == nil)
        self.imageView = [[UIImageView alloc] init];
    [self.imageView sd_setImageWithURL: [NSURL URLWithString:_downloadedimage] placeholderImage:[UIImage imageNamed:@"image.png"]];
    //...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多