ios - UITableView 与 estimatedRowHeight 反弹

标签 ios uitableview

我在 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/

相关文章:

ios - 获取安装的应用程序列表及其在 iOS 中的使用情况

ios - 在 iOS 7 中的两个简单 View Controller 之间进行切换的正确方法

ios - UITableView 不使用 UISearchBar 滚动

ios - UITableViewCell 的层在 heightForRowAt IndexPath 之后没有更新

objective-c - 将 KVO 添加到 UITableViewCell

ios - 选择另一个表行时如何删除 UITableViewCellAccessoryCheckmark 的自定义图标

iphone - 如何在 xcode4 中查看高分辨率

ios - NSCFString 0x2749a0 valueForUndefinedKey 此类对于键 push_type 不符合键值编码

iphone - 比较两个自定义单元格中 UILables 的值

iOS map View 问题/问题