Ios 为什么self.tablview.rowHeight不从情节提要返回高度?

Ios 为什么self.tablview.rowHeight不从情节提要返回高度?,ios,uitableview,heightforrowatindexpath,Ios,Uitableview,Heightforrowatindexpath,我需要以编程方式设置一行的高度,所有其他行都是在故事板中创建的具有不同高度的静态单元格 在我的代码中,默认情况下第5个单元格应该是“隐藏”的,因此我想将此行的高度设置为0.0。所有其他单元格都应该使用它们距故事板的高度,我正在使用方法tableView:heightforrowatinexpath来设置单元格的高度 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexP

我需要以编程方式设置一行的高度,所有其他行都是在故事板中创建的具有不同高度的静态单元格

在我的代码中,默认情况下第5个单元格应该是“隐藏”的,因此我想将此行的高度设置为0.0。所有其他单元格都应该使用它们距故事板的高度,我正在使用方法
tableView:heightforrowatinexpath
来设置单元格的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = self.tableView.rowHeight;

    if (indexPath.row == 4)
    {
        height = 0.0f;
    }

    return height;
}

问题是
self.tableView.rowHeight
总是将
658
作为高度返回,这是一个完全错误的值。

如果实现
heightforrowatinexpath
则需要为所有单元格设置一个值,否则会遇到类似的情况。您可以执行以下操作:

 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     switch (indexPath.row){
           case 4:
                return 0;

           default:

               static NSNumber *height;
               UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCustomCell"];
               height = @(cell.bounds.size.height);
               return [height floatValue];
      }
 }

第四牢房?那么我想这一行应该等于3!如果(indexath.row==3)sry是我的错,我将删除第5个单元格。但不幸的是,这不是问题所在。什么是self.tableView?它装订好了吗?我相信您不需要“self”。在第一行中,我也尝试了tableView.rowHeight,但这没有什么区别。实际上@Justafinger有一个有效点,您可以检查一下,rowHeight没有设置为658=>是的,我已经设置了。您正在
中使用该标识符。[tableView dequeueReusableCellWithIdentifier:@“MyCustomCell”]
是的,我使用的正是故事板中的标识符。