heightForRowAtIndexPath Change height variable to cell

I have three different custom cells of different heights. How should I use,

heightForRowAtIndexPath

To set the specific cell's height up. Something allong the lines of this.

if ([CellIdentifier isEqualToString:@"Cell"]) {
    return 200;}

No avail

Upvotes: 1

Views: 576

Answers (1)

Matthias Bauch
Matthias Bauch

Reputation: 90117

copy the code that figures out what cell to use from cellForRowAtIndexPath: to heightForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cel;
    NSString *CellIdentifier;
    // whatever code you use to figure out what cell to use
    if ([CellIdentifier isEqualToString:@"Cell"]) {
        // create & configure "Cell"-cell
    }
    else {
        // configure Standard cell
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *CellIdentifier;
    // whatever code you use to figure out what cell to use
    if ([CellIdentifier isEqualToString:@"Cell"]) {
        return 200.0f;
    }
    else {
        return 44.0f;
    }
}

Upvotes: 1

Related Questions