Strange UITableViewCellStyleSubtitle + [cell imageView] behaviors

狂风中的少年 提交于 2020-01-02 11:23:47

问题


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...



来源:https://stackoverflow.com/questions/8024811/strange-uitableviewcellstylesubtitle-cell-imageview-behaviors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!