开发者

How to make an expandable table view cell?

开发者 https://www.devze.com 2023-02-11 21:09 出处:网络
I would like a table view cell wh开发者_开发问答ich 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, a

I would like a table view cell wh开发者_开发问答ich 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号