我有一个UITableView
我想要它,这样当你点击单元格时,高度会动画到更高的高度(即:它会扩展)。我该怎么做?
答案 0 :(得分:17)
实际上很简单,为NSIndexPath
创建一个实例变量,我称之为selectedIndexPath
。然后,您需要做的就是在heightForRowAtIndexPath
中创建一个条件,以独立于其他单元调整此特定单元格的高度。
然后在didSelectRowAtIndexPath
中将所选索引路径iVar设置为所选单元格的路径,并在表格上调用开始/结束更新。单元格将自动展开,并带有漂亮的动画。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
selectedIndexPath = indexPath;
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath compare:selectedIndexPath] == NSOrderedSame) {
return 80;
}
return 40;
}