Images in a CustomTableCell gets resized upon click

70 Views Asked by At

This would be impossible to explain without a project, hence I uploaded a small DEMO on GitHub.

I don't think the constraints are wrong. The image should be fixed in its place. Initially SDWebImage retrieves the image from the cache, but once I click on the image, the image gets resized. (It gets smaller, see top image)

enter image description here

Funny enough in my demo the images show first as red squares. Once you click on them the imageView resizes and the actual image loads. This still shows the problem though.

enter image description here

It seems to me the initial cache is not resizing according to the constraints. Could that be true?

2

There are 2 best solutions below

0
Gaurav Sharma On BEST ANSWER

this fixes it:

[cell.imageView sd_setImageWithURL:imageURL
                      placeholderImage: nil
                             completed:^(UIImage image, NSError error, SDImageCacheType cacheType, NSURL *imageURL) {
                                 [cell setNeedsLayout];
                             }];
4
Anbu.Karthik On

I tried your Code

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BookmarkTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:bookmarkcellIdentifier forIndexPath:indexPath];

News *news = [_news objectAtIndex:indexPath.row];
cell.headLine.text = news.headLine;

[cell.newsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",news.imageUrlList]] placeholderImage:[UIImage imageNamed:@"iTagImageHolder"]];
 [cell.newsImage.layer setBorderWidth: 2.0];
[cell.newsImage.layer setBorderColor: [[UIColor blackColor] CGColor]];


return cell;
}

I got the output like

enter image description here

in storyboard I select the Autoresize subviews in `attributes inspectors

enter image description here