如何动态增加UITableViewCell的高度 [英] How can I increase the height of UITableViewCell dynamiclly
问题描述
我有一个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?
推荐答案
- 将所选索引存储在控制器中。
-
根据该索引返回单元格的高度:
- Store selected index in your controller.
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的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!