mercredi 13 juillet 2016

Scroll table view to bottom when using dynamic cell height

How can I scroll my table view to the bottom when using dynamic cell height?

For some reason this code does not work in this scenario:

[self.tableView scrollRectToVisible:CGRectMake(0, self.tableView.contentSize.height - self.tableView.bounds.size.height, self.tableView.bounds.size.width, self.tableView.bounds.size.height) animated:YES];

Thanks!

EDIT:

Here is a working fix that I have found myself. You can scroll to the bottom of the table view this code:

NSMutableArray *visibleCellIndexPaths = [[self.tableView indexPathsForVisibleRows] mutableCopy];


[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:visibleCellIndexPaths withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];

[self.tableView scrollRectToVisible:CGRectMake(0, self.tableView.contentSize.height - self.tableView.bounds.size.height, self.tableView.bounds.size.width, self.tableView.bounds.size.height) animated:YES];

Aucun commentaire:

Enregistrer un commentaire