Mafioso Mafioso - 4 months ago 136
iOS Question

Expand and Collapse first row on button click Objective - C

I want to expand and collapse the first row on button click. Button is in navigation bar. Can anybody help me in this.
Through Code.

Answer

When You click on the button,just check the state on 1st row of a table if it is collapsed then reload 1 row using reloadRowAtIndexpath method and change the size of the cell in size for row at indexpath.Same Procedure while collapsing.

For Expand and Collapse :-

-(IBAction) aButtonTapped:(id)sender {

[[self tableView] beginUpdates];
[[self tableView] reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem: 0 inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
[[self tableView] endUpdates]; }

Change the height in heightForRowAtIndexpath and apply check to see if the row is already expanded or not