尝试使用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?
}
感谢您的帮助。
答案 0 :(得分:2)
首先导入lib。
#import <SDWebImage/UIImageView+WebCache.h>
然后添加此行
[self.imageView setImageWithURL:[NSURL URLWithString:@"urlString" placeholderImage:[UIImage imageNamed:@"abc.png"]];
确保使用包含某些图片的有效网址,并且您分配给占位符的图片也应该在那里。
答案 1 :(得分:1)
看起来你没有初始化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"]];
//...
}