什么时候UITableView内容大小更新行插入/删除动画 [英] When does UITableView content size update with row insert/delete animation
问题描述
不幸的是,我在添加/删除行时找不到更新contentSize的好方法从UITableView中,但我发现一种方法来计算如果你知道你正在添加/删除单元格的索引路径。
使用索引修改行的路径,可以使用tableView:heightForRowAtIndexPath:方法计算各个单元格的高度,并将其添加到表视图的当前内容大小高度。下面是一个例子,如果你只添加一行:
[self.tableView insertRowsAtIndexPaths:@ [indexPathOfNewRow] withRowAnimation:UITableViewRowAnimationAutomatic] ;
CGFloat newCellHeight = [self tableView:self.tableView heightForRowAtIndexPath:indexPathOfNewRow];
CGFloat newContentSizeHeight = self.tableView.contentSize.height + newCellHeight
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 that the frame size/content size would be updated immediately even though the animation hasnt completed, but it does not seem to be that way. Any ideas?
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
这篇关于什么时候UITableView内容大小更新行插入/删除动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!