0

There is only one UIImageView in UITableViewCell, and the layout is exactly the same as contentView. I will show a set of images that look like a long picture.

My current practice is to download all the pictures in order, get the picture width and height, then get the actual height of UIImageView according to the screen width, and finally set heightForRow. This can work, but it is time consuming.

My question is, must I download the image before I can layout it? Is there a better way?

Update:

The ideal effect, without calculating the height, directly adapts to the cell height. Like label

Nullable
  • 761
  • 5
  • 17
  • 1
    check this maybe can help you https://stackoverflow.com/questions/44338392/swift-dynamic-uitableviewcell-size-based-on-image-aspect-ratio/44339968#44339968 – Reinier Melian Sep 25 '19 at 08:47
  • @ReinierMelian thanks, this is the method I am using now. I am wondering if there is a better way – Nullable Sep 25 '19 at 08:50
  • @ReinierMelian There is a problem with this method you provide, because `heightForRow` is always executed first, meaning that the height is always inaccurate when it has not started to slide. – Nullable Sep 25 '19 at 08:54
  • you can use a height by default until the image is loaded, in fact there is in the answer, defaultHeight – Reinier Melian Sep 25 '19 at 08:59
  • @ReinierMelian You are right, I ignored the refresh `UITableViewCell` – Nullable Sep 25 '19 at 10:24
  • If that answer helps you please upvote it thanks, let me know if any problem appears – Reinier Melian Sep 25 '19 at 10:34
  • @ReinierMelian Your method is correct, but it is the same as my previous practice and can work. I am not a problem, but an optimization. I want the effect like the layout `lable`, I don't need to calculate the height, I get the exact height of `cell` automatically. Because you didn't add the answer, I only approve of your comment. – Nullable Sep 26 '19 at 01:28
  • OK, let me work in an answer for your issue ;) – Reinier Melian Sep 26 '19 at 06:11

0 Answers0