如何创建可扩展表视图单元格?

问题描述:

我想要一个表格视图单元格,当你点击它的高度增加,以显示一些描述文本。当你再次点击它切换回较低的版本。这是可能的,如果是这样,我将如何实现呢?提前感谢

I would like a table view cell which when you tap it grows in height to reveal some description text. When you tap it again it toggles back to the less tall version. Is this possible, and if so how would I accomplish it? Thanks in advance

使用

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

-

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

当用户点击一行时,行高度在数组某处,然后调用tableview reload重绘。它将调用cellForRowAtIndexPath,并且由于知道哪个单元格具有很大的高度,因此返回该行的较大单元格,而heightForRowAtIndexPath将确保其正确显示。

when the user taps on a row, set the new row height in an array somewhere, then call tableview reload to redraw. It will call cellForRowAtIndexPath and since you know which cell has a large height, you return the larger cell for that row, and heightForRowAtIndexPath will ensure it is displayed correctly.