Sdwebimage: image in table cell is stretched after boot

I use SDWebImage in my iPhone project, and I use it to upload images to my table cell.

Original uploaded image 150 * 150. My placeholder image 32 * 32 (required size)

The first time the image is uploaded, sdwebimage does a great job of recalibrating the uploaded image according to the size of the splash screen (32 * 32). All is well.

However, when I go back and then return to the same page, the image is stretched and fills the entire height of cell.imageView. Is this normal behavior?

I need it to always keep the original size 32 * 32. Can you suggest how to do this?

EDIT : I found this link where another user is facing a similar problem (question open). The user also made a short youtube video to explain the problem.

Thoughts?

+4
source share
4 answers

try to do this for a specific size on cellForRowAtIndexPath:

UIImageView *addImage = [[UIImageView alloc] init]; [addImage setImageWithURL:[NSURL URLWithString:yourCellImageURL] placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; [addImage setFrame:CGRectMake(7, 3, 78, 57)]; [cell.contentView addSubview:addImage]; [cell setIndentationLevel:8]; 
+3
source

TL; DR . If your custom subclass of UITableViewCell has a @property IBOutlet UIImageView* called imageView , change your name to something else (like customImageView ) and it will work correctly.Read the rest of the answer why

I see that no one answered this, and I spent a whole week trying to find a solution to this, so this is what happened to me and how to prevent it from happening to you (thus fixing your problem).

I created a CustomTableViewCell that extends UITableViewCell .

I added @property (weak, nonatomic) IBOutlet UIImageView *imageView; to your custom cell. Everything seems beautiful so far, right?

Moreover, this is not so.

UITableViewCell already has an imageView property. First, iOS 7 uses your property, but then when the cell is reused, the UITableViewCell imageView is used , so all your restrictions or previously defined fixed sizes are ignored.

iOS 8 always uses an image from a UITableViewCell . therefore, the problem here is more obvious. Previous versions of iOS also had varying degrees of this problem, usually presenting very similar symptoms.

Decision? Either work with the UITableViewCell.imageView property yourself (add code to present the view) or create your own property with a different name , with which you can add restrictions (in case you use auto layout) to storyboards or xib.

+2
source

Try setting the correct UIImageView content mode

0
source

if you want to resize the image in SDWebImage. use this call.

 // Here we use the new provided setImageWithURL: method to load the web image [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { /*here you can change size of image */ }]; 
0
source

Source: https://habr.com/ru/post/1394079/


All Articles