我在xib中使用autoLayout作为我的customCell,因为我想根据文本为行设置可变高度。
现在我的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就会反弹。我不知道出了什么问题
此致 兰吉特
答案 0 :(得分:1)
这种情况正在发生,因为当您重新加载单元格时,表格视图会再次要求所有单元格的高度。任何位于滚动位置上方的单元格都会被询问其估计的行高,如果它们与当前高度不同,则会导致单元格改变高度,您将看到表格像这样反弹。
一旦您的单元格计算出它们的高度,您应该在某处缓存该值,然后实现tableView:estimatedHeightForRowAtIndexPath:
并返回单元格实际高度(如果它们有一个而不是您估计的高度)。
答案 1 :(得分:0)
您应该使用dequeueReusableCellWithIdentifier:forIndexPath
而不是您正在使用的版本。
您使用的那个将没有大小类,因为返回的单元格没有父级。由于尺寸等级的变化,从xcode 6开始出现这个问题。
尝试更改为此版本,该版本返回一个属于表格的单元格,从而继承超级视图的traitCollection并帮助布局正常工作。