我有一个 UITableView,其中包含 UITableViewCells 列表。我在方法 (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
中设置了 UITableViewCells 的高度。
但是,当选择 UITableViewCell
时,我需要增加它的高度。例如,UITableViewCell
的高度需要在单元格被选中时增加100像素,有人知道该怎么做吗?
最佳答案
- 将选定的索引存储在 Controller 中。
根据该索引返回单元格的高度:
CGFloat height = 30.0f; ... -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return indexPath.row == selectedIndex ? height+100 : height; }
在
didSelectRowAtIndexPath
方法中刷新 tableview 几何图形(beginUpdates
和endUpdates
之间的空 block 可以解决问题):- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ index = indexPath.row; [tableView beginUpdates]; [tableView endUpdates]; }
关于iphone - 如何动态增加 UITableViewCell 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3542260/