Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Height Programmatically for a Single UITableViewCell?

I need to set the height for a single UITableViewCell in my UITableView programmatically. How can I do this?

I need this one cell to be 150 pixels high and all the others can stay at their default 44 pixels in height.

Thanks.

like image 500
Josh Kahane Avatar asked Mar 22 '12 14:03

Josh Kahane


2 Answers

There is a delegate function for the UITableViewCell height.

Here you specify the indexPath of that particular cell and return your height for it

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == yourSection && indexPath.row == yourRow) {
        return 150.0;
    }
    // "Else"
    return someDefaultHeight;
}
like image 54
Max Avatar answered Jan 04 '23 03:01

Max


You will have to know, or figure out what cell index you want to make the taller one. Lets say its your first cell.

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == 0) { //change 0 to whatever cell index you want taller
        return 150;
    }
    else {
        return 44;
    }   
}
like image 31
Louie Avatar answered Jan 04 '23 04:01

Louie