我有一个UITableView包括一个UITableViewCell的列表。我在方法(CGFloat)中设置UITableViewCells的高度tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 。
I have an UITableView which includes a list of UITableViewCells. And I set the heights of UITableViewCells in method (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath.
但是,我需要增加 UITableViewCell 的高度。例如, UITableViewCell 的高度需要在选择单元格时增加100像素,有没有人知道如何做?
However, I need to increase the height of UITableViewCell when it is selected. For example, the height of UITableViewCell needs to increase 100 pixels when the cell is selected, does anyone know how to do it?
推荐答案
根据该索引返回单元格的高度:
Return cell's height depending on that index: CGFloat height = 30.0f; ... -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return indexPath.row == selectedIndex ? height+100 : height; }
在 didSelectRowAtIndexPath 方法( beginUpdates 和 endUpdates 之间的空块):
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ index = indexPath.row; [tableView beginUpdates]; [tableView endUpdates]; }
更多推荐
如何动态增加UITableViewCell的高度
发布评论