Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current cell height inside the heightForRowAtIndexPath?

I have a table with static cells. For one cell I want to change its height depending on the label's height (inside that cell) and at the same time leave all other cells height intact. How can I get current cell's height? Or maybe there is better approach?

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([indexPath section] == 2) {
        return self.myLabel.frame.origin.y *2 + self.myLabel.frame.size.height;
    } else {
        return ...; // what should go here, so the cell doesn't change its height?
    }
}
like image 638
sash Avatar asked Apr 10 '13 13:04

sash


2 Answers

You can call:

[super tableView:tableView heightForRowAtIndexPath:indexPath] 

in the else block so you don't have to worry if ever you changed the default height.

like image 73
talnicolas Avatar answered Oct 13 '22 01:10

talnicolas


You can get/set default height tableView.rowHeight, or you can store your height before changing cell height, so you can get default height from some variable;

like image 43
NSDmitry Avatar answered Oct 13 '22 01:10

NSDmitry