Strange UITableViewCellStyleSubtitle + [cell image

2019-05-27 15:44发布

问题:

This question's been bugging me for a month and i've been resisting posting about it, but I can hold out no longer. Here's what's going on:

I have an app with UITableViewCells, all initialized as UITableViewCellStyleDefault. For each one, I am setting the image view's image using the excellent SDWebImage package, which extends UIImageView to have a method for [UIImageView setImageWithURL:(NSURL*)url placeholderImage:(UIImage*)image].

The problem is that the images are showing up more narrow than they should be, on the tableView, but for some reason selecting a row makes it the correct size. So does scrolling the row off screen, then onscreen, then offscreen.

What method should I be using to force cells to redraw? I have found a few conflicting ideas and none of them have worked so far. I feel like there's a simple call to UITableView to UITableViewCell I'm missing out on. Also, where do I put this call? I have tried calls in cellForRowAtIndexPath and willDisplayCell .

Thanks for your help!

SDWebImage: https://github.com/rs/SDWebImage

回答1:

I solved the issue - I had to just make my SDWebImage placeholder images the same aspect ratio as the images I'm trying to load. As my server forces all my images to be 95x95, this was a relatively easy fix; I simply updated my placeholder.png to also be 95x95 (instead of some odd dimension it was, like 92x132)



回答2:

[[cell imageView] setContentMode:UIViewContentModeScaleAspectFit];

this line makes the imageview show the image in its original resolution but fit to the image view size.

the main drawback is if u have the images in different sizes then each image will show i different sizes.... it should not looks good...