Skip to content

Instantly share code, notes, and snippets.

@jaisonv
Created June 15, 2016 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaisonv/19ec45894f5a1e95a7bd7f51d6bb8fb5 to your computer and use it in GitHub Desktop.
Save jaisonv/19ec45894f5a1e95a7bd7f51d6bb8fb5 to your computer and use it in GitHub Desktop.
Expand / colapse UITableViewCell
NSInteger selectedRow = -1; // default selected row (here no one)
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == selectedRow) {
return 100; // expanded height
}
return 44; // colapsed height
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(self.selectedRow == indexPath.row)
selectedRow = -1;
else
selectedRow = indexPath.row;
//The magic that will call height for row and animate the change in the height
[tableView beginUpdates];
[tableView endUpdates];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment