自定义UITableViewCell高度会导致不正确的animation

我目前正在使用一个适用于大多数标准大小单元格的可视视图。 然而,有一些更大的,大约160分之一。

在这种情况下,在44pts高度处有2行,在下面插入较大的160pts行,在该部分的索引2处。

去除电话:

- (void)removeRowInSection:(TableViewSection *)section atIndex:(NSUInteger)index { NSUInteger sectionIndex = [self.sections indexOfObject:section]; NSIndexPath *removalPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex]; [self.tableView beginUpdates]; [self.tableView deleteRowsAtIndexPaths:@[removalPath] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView endUpdates]; } 

代表电话:

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { TableViewSection *section = [self sectionAtIndex:indexPath.section]; return [section heightForRowAtIndex:indexPath.row]; } 

部分电话:

 - (NSInteger)heightForRowAtIndex:(NSInteger)index { StandardCell *cell = (StandardCell *)[self.list objectAtIndex:index]; return cell.height; } 

手机:

 - (CGFloat)height { return 160; } 

我感到困惑的是,当我从表格中移除较大的行时,他们开始animation,移动到上面一行的下面。 但是,当他们到达某个点时,大约是animation方式的1/4,他们消失而不是完成animation。

看起来桌子好像只有44分钟的概念,然后一旦到了上面一排44磅的位置,桌子就从桌子上移开了。 我忽略了哪些细节会给表格提供一个正确的概念来自动生成删除行的animation?

谢谢你的帮助。

更新:我试着注释掉上面的高度函数(它覆盖了返回44的默认值)。 这会导致没有跳过的适当的animation。 FWIW

解决这个问题的一个方法是在删除之前将行高降低到44:

 //mark index paths being deleted and trigger `contentSize` update self.indexPathsBeingDeleted = [NSMutableArray arrayWithArray:@[indexPath]]; [tableView beginUpdates]; [tableView endUpdates]; //delete row [self.tableView deleteRowsAtIndexPaths:@[removalPath] withRowAnimation:UITableViewRowAnimationAutomatic]; [tableView endUpdates]; 

然后在你的heightForRowAtIndexPath

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if ([self.indexPathsBeingDeleted containsObject:indexPath]) { //return normal height if cell is being deleted [self.indexPathsBeingDeleted removeObject:indexPath]; return 44; } if (<test for tall row>) { return 160; } return 44; } 

有一点簿记继续追踪索引path被删除。 有可能更干净的方法来做到这一点。 这只是想到的第一件事。 这是一个工作示例项目 。