I'm using SDWebImage. I'm pulling the images in correctly from a web service API, but if the API I'm getting the response from doesn't have an image ("null"
), I want to realign my Table View Cell.
View Controller.m
[cell.imageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", imageURL]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
WebListCell.m
- (void)layoutSubviews {
[super layoutSubviews];
self.headlineLabel.frame = CGRectMake(134, 12.5, 130, 50);
self.descriptionLabel.frame = CGRectMake(134, 65, 130, 50);
self.imageView.frame = CGRectMake(12, 15, 96, 54);
//This Part Not Working
float limgW = self.imageView.image.size.width;
if (limgW == 1) {
self.headlineLabel.frame = CGRectMake(15, 15, 250, 50);
self.descriptionLabel.frame = CGRectMake(15, 65, 250, 50);
self.imageView.frame = CGRectMake(2, 2, 2, 2);
}
}
I was using this as a general guide: http://www.wrichards.com/blog/2011/11/sdwebimage-fixed-width-cell-images/
(My placeholder image right now is just 1px by 1px)
So basically my problem is I can't find a good "if" statement for when there is no image and I want to realign my Table View Cell.
Any advice on an easy "if" statement?
EDIT:
Using this code now, which works, except I'm getting a warning that says "Capturing cell
strongly in this block is likely to lead to a retain cycle"
[cell.imageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", imageURL]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if(image == nil) {
//realign your table view cell
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://website.com/image1"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
];
}
}];