奇怪的 UITableViewCellStyleSubtitle + [细胞图像视图]行为
这个问题已经困扰我一个月了,我一直拒绝发表有关它的文章,但我不能再坚持了。事情是这样的:
我有一个带有 UITableViewCell
的应用程序,全部初始化为 UITableViewCellStyleDefault
。对于每一个,我都使用优秀的 SDWebImage 包设置图像视图的图像,该包扩展了 UIImageView 以具有 [UIImageView setImageWithURL:(NSURL*)url placeholderImage:(UIImage*)image] 的方法。
问题在于,在 tableView 上,图像显示的宽度比应有的窄,但由于某种原因,选择一行使其大小正确。将行滚动到屏幕之外,然后滚动到屏幕上,然后滚动到屏幕外也是如此。
我应该使用什么方法来强制单元格重绘?我发现了一些相互矛盾的想法,但迄今为止都没有奏效。我觉得有一个对 UITableView 到 UITableViewCell 的简单调用我错过了。另外,我该把这个电话放在哪里?我尝试过在 cellForRowAtIndexPath
和 willDisplayCell
中进行调用。
感谢您的帮助!
SDWebImage: https://github.com/rs/SDWebImage
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 UITableViewCell
s, 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决了这个问题 - 我必须使我的
SDWebImage
占位符图像与我尝试加载的图像具有相同的宽高比。由于我的服务器强制我的所有图像均为 95x95,因此这是一个相对简单的修复;我只是将placeholder.png
更新为 95x95(而不是一些奇怪的尺寸,例如 92x132)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 myplaceholder.png
to also be 95x95 (instead of some odd dimension it was, like 92x132)该行使图像视图以其原始分辨率显示图像,但适合图像视图大小。
主要缺点是,如果你有不同尺寸的图像,那么每个图像都会显示不同的尺寸......它看起来应该不太好......
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...