I am trying to expand a UITableViewCell to reveal more content. So far i've got the animation down, but my problem is the new content appears before the animation is complete. Here is my code:
ps the description label and read button both start off as hidden when the cell is configured.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.selectedRow = indexPath;
SDJCell *cell = (SDJCell *)[tableView cellForRowAtIndexPath:indexPath];
[tableView beginUpdates];
[tableView endUpdates];
cell.descriptionLabel.hidden = NO;
cell.readButton.hidden = NO;
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
SDJCell *cell = (SDJCell *)[tableView cellForRowAtIndexPath:indexPath];
[tableView beginUpdates];
[tableView endUpdates];
cell.descriptionLabel.hidden = YES;
cell.readButton.hidden = YES;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if(selectedRow && indexPath.row == selectedRow.row) {
return 100;
}
return 44;
}
Any ideas for how I can reveal this extra content after the cell is done expanding??
Thanks!!
To change the height of tableView cell in ios dynamically, i.e resizing the cell according to the content available, we'll need to make use of automatic dimension property. We'll see this with the help of an sample project.
I had the exact same problem. The solution is to set the autoresizing mask of the cell, so that it resizes along with its superview.
cell.autoresizingMask = UIViewAutoresizingFlexibleHeight;
cell.clipsToBounds = YES;
you could also do this in sotoryboard, both flags can be set under identity inspector
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With