一个单元格(UITableView)可以实时改变它的高度吗?

Can a cell (UITableView) change its height in real time?

我有一个带有标签的单元格,有时标签文本会发生变化,单元格应该稍微展开一点。我正在使用自动布局和可变高度单元格(您知道,UITableViewAutomaticDimension 和 estimatedRowHeight)。除非在修改标签后我调用 reloadData 或重新加载该特定单元格,否则它似乎不起作用。 那是正常的吗?有什么方法可以自动执行此操作,或者无需使用视图控制器重新加载现在应该具有另一个高度的单元格?谢谢。

try this one 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[[arrFeed objectAtIndex:indexPath.section] objectForKey:@"post_keywords"] isEqualToString:@""])
    {
        int heigthHeading = [self getHeightForText:[[arrFeed objectAtIndex:indexPath.section] objectForKey:@"post_heading"] withFont:[UIFont systemFontOfSize:17.0] andWidth:245.0];


        return 25+heigthHeading;
    }
    else
    {

         int heigthHeading = [self getHeightForText:[[arrFeed objectAtIndex:indexPath.section] objectForKey:@"post_heading"] withFont:[UIFont systemFontOfSize:17.0] andWidth:245.0];


        return 25+heigthHeading;

    }
}

我在我的一个应用程序中遇到了类似的问题,我所做的是 添加 2 个约束条件,设 d 为标签的默认高度 1.标签高度>=d,优先级=750 2.高度=d,优先级=1000 和 uitableview 单元格属性到 UITableViewAutomaticDimension 这对我有用。

使单元格高度动态化(您也可以像这样在同一个单元格上添加多个标签并且您的单元格增加的高度取决于标签文本)

为标签添加四个约束(顶部、底部、前导、尾随)

设置第0行数和换行模式自动换行

添加这两个委托方法

-(CGFloat)tableView:(UITableView )tableView estimatedHeightForRowAtIndexPath:(NSIndexPath )indexPath 
{
    return 44;
} 

-(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath 
{
   return UITableViewAutomaticDimension;
}