0

I have grouped UITableView with cells size of 400. Inside I have UIImageView with images from NSURL. How can I make those images to determine uitableviewcell height ? How can I even get real image size (at least height, it's more important than width in my case) from downloaded image ??

Its something like 9gag app. Most images would be about 3/4 of cell and almost 1/2 of screen but some images (like funny memes) where you have dialogs and which are very long should strech uitableviewcell on 2 screens (need scrolling to see whole image).

zhuber
  • 5,364
  • 3
  • 30
  • 63

1 Answers1

1

You will need to create an array to hold the downloaded images and their metadata. This array could just be in your UITableViewController for simplicity sake.

When you download your images, save them into your images array.

Then, in your -tableView:heightForRowAtIndexPath: method, you query this array for the heights from the saved images - for example,

-(float)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return [self.images objectAtIndex:indexPath.row].size.height + 50;
}

This will make the cells 50px taller than the image's height. Note that you will need to tell the table to update cell heights for it to take effect.

Community
  • 1
  • 1
Tim
  • 14,447
  • 6
  • 40
  • 63