gpt4 book ai didi

ios - tableView 单元格中标签的框架大小不会改变

转载 作者:行者123 更新时间:2023-11-29 02:42:54 24 4
gpt4 key购买 nike

我在 Storyboard中工作。我有从 tableViewVC 继承的 View Controller 。在那个 vc 中,我有带有一两行文本的单元格。如果我有一行,我只是将文本分配给自定义 Cell 中的自定义 textLabel。如果我有 2 行,我会调整标签框的大小。但是在加载表格时它不起作用。只有在我向上/向下滚动 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;
}

http://s23.postimg.org/8tszefzbf/Screen_Shot_2014_08_27_at_10_01_10_PM.png

第一个屏幕后,我按下 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;
}

关于ios - tableView 单元格中标签的框架大小不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25535070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com