Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expanding UITableViewCell

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!!

like image 885
Sean Danzeiser Avatar asked Apr 19 '12 01:04

Sean Danzeiser


People also ask

How do I change cell height in Swift?

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.


1 Answers

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

like image 109
aryaxt Avatar answered Sep 19 '22 06:09

aryaxt