0

I am parsing data, which I'd like to display in a UIWebView within the contentView of a cell. The problem: The height of the cell is loaded before I get the real height of the UIWebView. So I need to refresh the height of the cell, after the webView has finished loading:

[self.tableView reloadData];

does not reload the cell height (but it would refresh without animation, exactly what I need) and

[self.tableView beginUpdates];
[self.tableView endUpdates];

or

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

are with an animation, even if I use UITableViewRowAnimationNone.

What can I do to refresh height after viewDidLoad without animation?

filou
  • 1,609
  • 5
  • 26
  • 53

1 Answers1

-1

Where exactly did you specify the cell height?

Have you tried using the UITableViewDelegate method -tableView:heightForRowAtIndexPath:.

Like so:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [[_cellArray objectAtIndex:indexPath.row] getDynamicHeight];
}

At least, that worked for me.

reggian
  • 627
  • 7
  • 21
  • Yes, right. But you forgot that the height of the webView is dynamic. So I have to update the cell height AFTER I parsed the data. – filou May 14 '13 at 21:55
  • I have struggled with a problem like that and solved it by saving a reference to all the cells (in my case there were not so many) and listed through the array using `indexPath.row` and returning the already loaded UIWebView height. I have edited the answer a bit. – reggian May 14 '13 at 21:59
  • In my case it is one cell per view, and every cell has got another size. – filou May 14 '13 at 22:07
  • If I understand you correctly, you have multiple cells containing a single dynamic-size UIWebView. If that is the case, my approach would be to have your custom cells in an array and using the code in my answer to get and return the height of the loaded UIWebView. – reggian May 14 '13 at 22:14
  • Do you mean the height of the cells? And how does it work? I mean the height is called just one time and I do not have the height when this happens. – filou May 14 '13 at 22:22
  • After your web view has finished loading (as I understand you should have your heights known at that time) call the `reloadData` on your table view. The `-tableView:heightForRowAtIndexPath:` should get called once for each cell (provided that you have set your delegate). – reggian May 14 '13 at 22:33
  • As soon as the webView got it's height, I am saving the height as a float value. In `-tableView:heightForRowAtIndexPath:` I call `return ([self.productDescriptionCellHeight floatValue] + 60);`. Of course it is 0 at the beginning. The point is, everything is prepared, but the height will not be reset.. – filou May 14 '13 at 22:43