Is there a way to expand/contract UITableViewCells on the fly?
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.
精彩评论