iphone - 如何动态增加 UITableViewCell 的高度

标签 iphone cocoa-touch uitableview

我有一个 UITableView,其中包含 UITableViewCells 列表。我在方法 (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 中设置了 UITableViewCells 的高度。

但是,当选择 UITableViewCell 时,我需要增加它的高度。例如,UITableViewCell的高度需要在单元格被选中时增加100像素,有人知道该怎么做吗?

最佳答案

  1. 将选定的索引存储在 Controller 中。
  2. 根据该索引返回单元格的高度:

    CGFloat height = 30.0f;
    ...
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return indexPath.row == selectedIndex ? height+100 : height;
    }
    
  3. didSelectRowAtIndexPath 方法中刷新 tableview 几何图形(beginUpdatesendUpdates 之间的空 block 可以解决问题):

    - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        index = indexPath.row;
        [tableView beginUpdates];
        [tableView endUpdates];      
    }
    

关于iphone - 如何动态增加 UITableViewCell 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3542260/

相关文章:

ios - 在 UITableview 的编辑模式下滚动时删除按钮消失了

ios - 在 UITableView ios 的每个部分中选择一行?

iphone - iOS中不同tableView中单元格的高度

iphone - 供应商标识符

iphone - 我应该如何为 iPhone 实现可编辑的丰富文档 View ?

cocoa-touch - 在 NSUserDefaults 中加载数据

ios - 从 Xcode 重新安装应用程序时 iPhone 模拟器报告错误

iphone - 当在 Objective-C 中调用 dealloc 时

objective-c - 在 Cocoa 中以有效的方式提取 NSString 的一部分

ios - 如何计算 UILabel 的高度?