Ios 调用insertRowsAtIndexPath时,单元格大小会被压缩

Ios 调用insertRowsAtIndexPath时,单元格大小会被压缩,ios,objective-c,uitableview,Ios,Objective C,Uitableview,当插入rowatindexpath时。。。当单元格大小调整为非常紧凑的大小时。但是当这些细胞消失在视野之外,又回来时,它们又恢复了正常 代码如下: - (IBAction)addRow:(id)sender { NSInteger row = [self.rowArray count] - 1; [self.rowArray insertObject:@"cellIDRowSeven" atIndex:row]; NSIndexPath *indexPath = [NS

当插入rowatindexpath时。。。当单元格大小调整为非常紧凑的大小时。但是当这些细胞消失在视野之外,又回来时,它们又恢复了正常

代码如下:

- (IBAction)addRow:(id)sender
{
    NSInteger row = [self.rowArray count] - 1;
    [self.rowArray insertObject:@"cellIDRowSeven" atIndex:row];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
    [self.myTableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
{
    return UITableViewAutomaticDimension;
}

(当我执行
[self.myTableView reoladData];
时,它工作正常,但我没有获得动画效果。)

您为
tableView
设置了
估计值吗?顺便说一句,如果所有单元格都有相同的高度,最好只做
self.tableView.rowHeight=UITableViewAutomaticDimension

我不能做
EstimatedRowheaight
,因为所有单元格都有不同的高度。我的一个项目中也有一个具有动态单元格高度的表视图。只要设置了自动布局约束,则estimatedRowHeight将仅作为表视图渲染单元的准则。它是“估计”的,所以你仍然有动态单元格高度。在某种程度上,我认为如果使用
UITableViewAutomaticDimension
,则需要设置
estimatedRowHeight
。(但我不是100%确定。我总是同时使用它们。)我可以使用
UITableViewAutomaticDimension
来估计行高吗?@Mike,我认为
UITableViewAutomaticDimension
仅用于行高,因为它是“自动”的,所以您必须提供估计行高。。。这只是我自己的理解。