I have four UIView which is placed on UITableViewCell just like each cell contain one view. And I want to expand the TableViewCell dynamically when click on perticular cell and also adjust following cell. How it can be done?
Asked
Active
Viewed 71 times
-1
-
2Have you tried something? – 0yeoj Aug 10 '15 at 12:53
-
This questions is answered here: http://stackoverflow.com/questions/3069339/how-to-dynamically-resize-uitableviewcell-height – Arie Litovsky Aug 10 '15 at 15:26
2 Answers
1
You'll need to call tableView.beginUpdates()
, then call tableView.reloadRowsAtIndexPaths(:withRowAnimation:)
on the row index you want to change, and tableView.endUpdates()
.
You'll also need to implement tableView(:heightForRowAtIndexPath:)
. That should return the 'standard' height for most rows (44.0 by default), and then a larger value for the expanded row.

iAnurag
- 9,286
- 3
- 31
- 48

Ben Gottlieb
- 85,404
- 22
- 176
- 172
0
Some sample code:
@implementation ViewController {
NSIndexPath *indexPathToExpand;
}
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
if(indexPath == indexPathToExpand)
return expandedHeight;
else
return defaultHeight;
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
indexPathToExpand = indexPath;
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
@end

Vinod Vishwanath
- 5,821
- 2
- 26
- 40