开发者

Is there a way to expand/contract UITableViewCells on the fly?

开发者 https://www.devze.com 2023-02-25 19:29 出处:网络
I would like to have a custom UITableViewC开发者_如何学JAVAell that displays limited data while unselected, but then expand to show more details when selected.

I would like to have a custom UITableViewC开发者_如何学JAVAell that displays limited data while unselected, but then expand to show more details when selected.

The issue I have is how do I adjust the size of the cell during a select/deselect event?


Make a sub-class of UITableViewCell, and override the drawRect() method. In your view controller's didSelectRowAtIndexPath, you can switch between the contracted and expanded states. You can change frame sizes, add or remove sub-views, add more data, whatever you need to do.


I was doing it not so long ago. To adjust the size you need to make UITableView call heightForRowAtIndexPath again. It will cause redrawing of cell. Use

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation 

in order to do that. If you set animation to YES it will nicely animate expanding of your cell. Also to adjust cell, setSelected: in your UITableViewCell subclass may be helpfull.

0

精彩评论

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

关注公众号