Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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