1

In my apps, i have created table view and displayed the images and the labels in the table view. I have downloaded the image and set the image height into the another class and i have passed the image height value using delegates. In my problem is, heightForRowAtIndexPath method is call very earlier and it never calls again. So how i set the cell height depends on the image height?

//appDelegate.imageHeight - Image height delegate value.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

 NSLog(the height of the image is --------------------------%f, appDelegate.imageHeight);
 In Console:
     the height of the image is --------------------------0.000000
     the height of the image is --------------------------0.000000
     the height of the image is --------------------------0.000000
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     NSLog(the height of the image is --------------------------%f, appDelegate.imageHeight);
     In Console:

        the height of the image is --------------------------98.567039
        the height of the image is --------------------------300.000000
        the height of the image is --------------------------232.288406
 }

Is any possible to call the heightforRowAtIndexPath method inside the cellForRowAt method. Because i have set the cell frame size and height depends on the image height. So how can i set the cell height depends on the image height?, please guide me.

Thanks!

Pugalmuni
  • 9,350
  • 8
  • 56
  • 97
  • 1
    I'm trying to add similar behaviour to an app; found this post, which might have a solution? - the answer saying call [tableView beginUpdates]; and [tableView endUpdates] looks promising? : http://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected – petert Jan 07 '11 at 11:59

2 Answers2

1

here are some suggestions UITableView flexible/dynamic heightForRowAtIndexPath

Community
  • 1
  • 1
Sorin Antohi
  • 6,145
  • 9
  • 45
  • 71
1

heightForRowAtIndexPath method is called before cellForRowAtIndexPath, so you need to know height of images you are displaying in your cells. Maintain the dictionary or array that contains height of images which get passed to this class and use it to set the height of cell accordingly

Javal Nanda
  • 1,828
  • 3
  • 14
  • 26
  • Thanks for the reply. But the image height values only gets in the cellForRowAtIndexPath method, If i create any dictionary or array, then how can i pass those values into the heightForRowAtIndexPath method? so is any possible to call "heightForRowAtIndexPath" inside the cellForRowAtIndex method or some other solutions possible? Thanks. – Pugalmuni Jan 07 '11 at 12:04
  • how is it possible that whatever you do for computing image height in cellForRowAtIndex cannot be done at the time your view get appears? Tell me how do you get your images? through parsing or something? and what actually you do in cellForRowAtIndex path? – Javal Nanda Jan 07 '11 at 12:09
  • Yes Nanda, I have used Async library for improvising the lazy loading.The image height values are passed to the another class, so that the image height values only gets the table view cell scrolls,ie) cellForRowAtIndex method. Thanks! – Pugalmuni Jan 07 '11 at 13:28