How to update UITableViewCell height after loading a View table

A user UITableViewCellincludes an image that is downloaded asynchronously from the Internet, and its size / aspectRatio is not known in advance, so there is no way to return the exact height of the cell to tableView:heightForRowAtIndexPath:.

I can return the estimated height in the delegate method, but I need to inform the tableView about the change in cell height when loading the image. How should I do it?

  • reloadData will be too heavy, considering every time the image is loaded, the entire tableView is updated.
  • reloadRowsAtIndexPaths:withRowAnimation:also not good. Since the cell itself does not change, it is necessary to update its height.
+4
source share
3 answers

, , [self.tableView reloadData];, - .

+3

- . , , . . . .

    [YourTableView reloadRowsAtIndexPaths:[YourTableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationAutomatic];

    [YourTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:YourImageCompletelyDownloadRow inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
+1

,

[tableview reloadData];

:

UITableView , , reloadData.

Therefore, only visible cells will be reloaded.

+1
source

Source: https://habr.com/ru/post/1539387/


All Articles