4

I am getting the image's URL at run time and  download & display these images in a table. Images are  downloading asynchronously(using SDWebImage). What is more important is that I want to display all these images with their actual sizes. First time ,the table is loading fine, I have more than 5 section(each section contains one row) and when I scroll the table and try to update sections by using reloadSections, then the table shows with wrong cell image height. Can anybody help me out with this? Note: I am using UITableViewAutomaticDimension

[_imageViewSharedImage sd_setImageWithURL:[NSURL URLWithString:[_popUpManager.popUpDetails valueForKey:@"photo"]] placeholderImage:[UIImage imageNamed:@"placeholderBackground"] options:SDWebImageProgressiveDownload completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
     UIImage *croppedImage=[Util adjustImageSizeWhenCropping:image];     
     [_imageViewSharedImage setFrame:CGRectMake(_imageViewSharedImage.frame.origin.x,_imageViewSharedImage.frame.origin.y,croppedImage.size.width,croppedImage.size.height)];
     [_imageViewSharedImage setImage:croppedImage];
     [self setNeedsLayout];
     [self updateConstraintsIfNeeded];

}];
Leo
  • 24,596
  • 11
  • 71
  • 92

1 Answers1

0

When using UITableViewAutomaticDimension, you have to specify auto layout constraints from top to bottom for all the items in your cell's content view. Hope you have done that.

And while using auto layout, you should take care to not adjust the frame. If you want to do so, do it using constraints. Make an outlet for the height constraint and width constraint of your imageViewSharedImage and set its constant to the values you require.

_imageViewHeightConstraint.constant = croppedImage.frame.size.height;
_imageViewWidthConstraint.constant = croppedImage.frame.size.width;

Then call layoutIfNeeded.

Skywalker
  • 1,590
  • 1
  • 18
  • 36