我有一个UITableView,其中包含一个UITableViewCells列表。我在方法(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
中设置了UITableViewCells的高度。
但是,我需要在选择时增加UITableViewCell
的高度。例如,当选择单元格时,UITableViewCell
的高度需要增加100像素,是否有人知道如何操作?
答案 0 :(得分:11)
根据索引返回单元格的高度:
CGFloat height = 30.0f;
...
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return indexPath.row == selectedIndex ? height+100 : height;
}
在didSelectRowAtIndexPath
方法中刷新tableview几何图形(beginUpdates
和endUpdates
之间的空白区块可以解决问题):
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
index = indexPath.row;
[tableView beginUpdates];
[tableView endUpdates];
}
答案 1 :(得分:0)
制作代表方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
返回(新)正确的高度,并使表格视图重新加载给定的路径。