Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom cell with variable height
    text
    copied!<p>I´m using custom cells in a TableView. </p> <p>The cell height is calculated based on an NSString that is loaded in a UILabel of the cell. The size is calculated using this function</p> <pre><code>(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; { NSString *text = [self getTableViewRow:tableView index:indexPath]; CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f); CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; CGFloat height = MAX(size.height, 44.0f); return height + (CELL_CONTENT_MARGIN * 2) + 60; </code></pre> <p>}</p> <p>The size is calculated correctly but when the cell is loaded to the uiTableView, the row has the correct height but the cell does not have.</p> <p>This is where i create my cell</p> <pre><code>//Com Custom Cell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"CustomCellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCellApresentacao" owner:self options:nil]; if ([nib count] &gt; 0 ) cell = self.tvCell; else NSLog(@"Falhou a carregar o xib"); } NSInteger row = [indexPath row]; if(self.myTableView1 == tableView) labelDescricaoApresentacao.text = [listData1 objectAtIndex:row]; else if (self.myTableView2 == tableView) labelDescricaoApresentacao.text = [listData2 objectAtIndex:row]; else labelDescricaoApresentacao.text = [listData3 objectAtIndex:row]; return cell; } </code></pre> <p>i tried to change the cell height in this method using </p> <pre><code>cell.frame.size.height </code></pre> <p>but it still didn´t loaded the correct heigth.</p> <p>Do i have to do anything in the xib of the customCell? How should i update the cell heigth to the same size has the row? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload