我在 xib 中为我的 customCell 使用 autoLayout,因为我想根据文本为行设置可变高度。
现在在我的 VC.m 中
我正在使用这些代码行
- (void)viewdidLoad
{
m_tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
m_tableView.estimatedRowHeight = 97.0;
m_tableView.rowHeight = UITableViewAutomaticDimension;
}
这是我的 cellForRow 函数
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *tableCell = (NotesCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (tableCell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
tableCell = [nib objectAtIndex:0];
}
// Configure the cell...
//This code is used to make the separator full width. Also the tableview separator insets should be set to zero
tableCell.layoutMargins = UIEdgeInsetsZero;
tableCell.preservesSuperviewLayoutMargins = NO;
return tableCell;
}
所以现在每当我更新一行时,我都会调用这些代码行
[m_tableView beginUpdates];
[m_tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:m_indexPath] withRowAnimation:UITableViewRowAnimationFade];
[m_tableView endUpdates];
当我这样做时,Tableview 只会反弹。我不知道出了什么问题
问候 兰 git
最佳答案
发生这种情况是因为当您重新加载单元格时,表格 View 会再次询问所有单元格的高度。滚动位置上方屏幕外的任何单元格都将被要求提供它们的估计行高,如果它们与当前高度不同,它将导致单元格改变高度,你会看到表格像那样弹跳。
一旦你的单元格计算出它们的高度,你应该将该值缓存在某个地方,然后实现 tableView:estimatedHeightForRowAtIndexPath:
并返回单元格的实际高度(如果它们有一个而不是你的估计高度)。
关于ios - UITableView 与 estimatedRowHeight 反弹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29101840/