Ios 标签';在tableView单元格中,s帧大小不变

Ios 标签';在tableView单元格中,s帧大小不变,ios,objective-c,uitableview,tableview,Ios,Objective C,Uitableview,Tableview,我在故事板工作。我从tableViewVC继承了视图控制器。在vc中,我有一行或两行文本的单元格。如果我有一行,我只需将文本指定给自定义单元格中的自定义textLabel。如果我有两行,我会调整标签框架的大小。但在加载表时,它不起作用。只有在向上/向下滚动tableView后,我才能在单元格中看到调整大小的标签。我怎样才能修好它 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIn

我在故事板工作。我从tableViewVC继承了视图控制器。在vc中,我有一行或两行文本的单元格。如果我有一行,我只需将文本指定给自定义单元格中的自定义textLabel。如果我有两行,我会调整标签框架的大小。但在加载表时,它不起作用。只有在向上/向下滚动tableView后,我才能在单元格中看到调整大小的标签。我怎样才能修好它

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
OptionItem *item = _currentOptionsList[indexPath.row];

static NSString *CellIdentifier = @"OptionSimpleCellIdentifier";
OptionSimpleCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

cell.titleLabel.text = item.title;
cell.haveDetail = item.haveDetailItems;
cell.selectedSimpleOption = item.simpleSelected;
if (item.haveSelectedDetailItem)
{
    cell.detailLabel.text = [item.detailItems[item.indexOfSelecteDetaildItem] title];

} else {
    cell.detailLabel.text = nil;
    cell.detailImageView.image = nil;
}


CGFloat textHeight = [Calculatons getLabelHeightForText:item.title andWidth:225 withFont:kFontListCell withMaxHeight:0];//19 - 39
CGRect rect = cell.titleLabel.frame;

NSLog(@"textHeight = %f cell.height = %f titleLabel.height %f \n",textHeight, cell.frame.size.height, cell.titleLabel.frame.size.height);

if (textHeight > 21)
{
    rect.size.height = 41;
    cell.titleLabel.frame = rect;
}


  //nothing of this not works
  [cell.titleLabel layoutIfNeeded];
    [cell.titleLabel setNeedsLayout];
[cell.titleLabel setNeedsUpdateConstraints];
  [cell.titleLabel setNumberOfLines:0];

return cell;
}

在第一个屏幕之后,我按下VS。第二个屏幕是我上下滚动表格后显示的屏幕


在我按下VC之后,我需要第二个屏幕作为结果。

尝试在代码的前面使用它,在单元格初始化之后,而不是在将值设置为标签之后

CGFloat textHeight = [Calculatons getLabelHeightForText:item.title andWidth:225 withFont:kFontListCell withMaxHeight:0];//19 - 39
CGRect rect = cell.titleLabel.frame;

NSLog(@"textHeight = %f cell.height = %f titleLabel.height %f \n",textHeight, cell.frame.size.height, cell.titleLabel.frame.size.height);

if (textHeight > 21)
{
    rect.size.height = 41;
    cell.titleLabel.frame = rect;
}