How to make an expandable table view cell?

南笙酒味 提交于 2019-12-08 02:11:38

问题


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


回答1:


Use

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

--

In

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

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.



来源:https://stackoverflow.com/questions/5050534/how-to-make-an-expandable-table-view-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!