Reputation: 229
I'm trying use SDWebImage for downloading image from a web. But it's not working. How can I fix it?
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?
}
Thanks for your help.
Upvotes: 0
Views: 3496
Reputation: 2120
Looks like you not initialized imageview. Try to do it before.
- (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"]];
//...
}
Upvotes: 1
Reputation: 1412
Firstly Import the lib.
#import <SDWebImage/UIImageView+WebCache.h>
and then add this line
[self.imageView setImageWithURL:[NSURL URLWithString:@"urlString" placeholderImage:[UIImage imageNamed:@"abc.png"]];
Make sure you using a valid url that contain some image and the image you are assigning to your placeholder should be there aswell.
Upvotes: 2