4
votes

I am trying to populate UITableView with UITableViewCell of different heights. I am returning the right size in

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

It looks likes that the height of the cell is being used by the framework in someway, but the dequeued cells are still of the same size.

I have also tried using setFrame: on individual cells, but still this does not have any effect. Am I missing something

for example

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    if (condition 1)
      return 60;
    else if (condition 2)
      return 100;
    return 44;
}

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
static NSString *CellIdentifier = @"TableViewCell";


    TableViewCell *cell = (TableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];   
    }

   return cell;
}
1

1 Answers

2
votes

So, here is the deal. In the implementation of TableViewCell, I was creating complex layout. And by mistake for one of the UILabels I had [self addSubview: ], instead of [self.contentView addSubView:] this was the culprit.