Created
June 15, 2016 03:59
-
-
Save jaisonv/19ec45894f5a1e95a7bd7f51d6bb8fb5 to your computer and use it in GitHub Desktop.
Expand / colapse UITableViewCell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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