UITableViewCell of different heights

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

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

It looks like the cell height is being used by the wireframe in some way, but the selected cells are still the same size.

I also tried using setFrame: on individual cells, but still it has no effect. I'm missing something

eg

    - (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;
}
+3
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1783164/


All Articles