When does UITableView content size update with row insert/delete animation

前端 未结 3 1742
情书的邮戳
情书的邮戳 2021-01-12 02:08

I am curious when the UITableView\'s content size is updated after doing an insert/delete animation call. I figured it would be like most [UIView animation...] blocks in tha

3条回答
  •  死守一世寂寞
    2021-01-12 02:21

    Unfortunately, I haven't been able to find a good way to update the contentSize when adding/deleting rows from a UITableView either, but I did find a way to calculate what it will be if you know the index paths of the cells you are adding/removing.

    Using the index path of the modified rows, you can calculate the heights of the respective cells with the tableView:heightForRowAtIndexPath: method and add it to the current content size height of the table view. Here's an example if you're adding just one row:

    [self.tableView insertRowsAtIndexPaths:@[indexPathOfNewRow] withRowAnimation:UITableViewRowAnimationAutomatic];
    CGFloat newCellHeight = [self tableView:self.tableView heightForRowAtIndexPath:indexPathOfNewRow];
    CGFloat newContentSizeHeight = self.tableView.contentSize.height + newCellHeight
    

提交回复
热议问题