I´m using custom cells in a TableView.
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
(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;
}
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.
This is where i create my cell
//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] > 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;
}
i tried to change the cell height in this method using
cell.frame.size.height
but it still didn´t loaded the correct heigth.
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?