如何创建可扩展表视图单元格? [英] How to make an expandable table view cell?

查看:138
本文介绍了如何创建可扩展表视图单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于如何创建可扩展表视图单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆