从iOS7开始,在我的UITableView顶部有额外的空间它有一个UITableViewStyleGrouped样式。

这里有一个例子:

tableview从第一个箭头开始,有35个像素的无法解释的填充,然后绿色的头是一个由viewForHeaderInSection返回的UIView(其中section为0)。

有人能解释一下这个35像素的数量是从哪里来的吗?我如何才能在不切换到UITableViewStylePlain的情况下摆脱它?


更新(回答):

在iOS 11及更高版本中:

tableView.contentInsetAdjustmentBehavior = .never

当前回答

None of the previous answers worked for me. What did end up working for my situation (which was seeing that padding after dynamically adding a header to my Table View) was selecting the Navigation Bar from the Document Outline and rechecking the Translucent box (contrary to some answers that were saying to force it to be translucent). I had previously unchecked it because it had made my red look a little orange, but I could not try the solution of reordering the elements in the scene since the Table View was the only element in this scene. This solution works as long as you are okay with the Navigation Bar's color having a translucent layer over it. Hope this helps :)

其他回答

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return CGFLOAT_MIN;
}

这就是所有的朋友们!

如果你在iOS 15或更高版本中遇到这个问题,请执行以下操作:

if #available(iOS 15.0, *) {
    self.tableView.sectionHeaderTopPadding = 0
}

我有一个VC与容器在它(btw是一个导航控制器的一部分),并嵌入其中是一个TableVC。

选择我的TableVC,查看属性面板:

取消勾选自动调整滚动插入 取消检查顶部栏下的延伸边

然后我设置了容器相对于父视图的自动约束:

容器的观点。top = ParentView。顶边

这为我完成了以下任务:

保持桌面拉到顶部,但就在我的导航栏下面 刷新后,表返回到这个位置,而不是像以前那样在导航栏下向上+ 在实际的底部滚动表底部后,不缺它

我用这个设置进行了大量的试验和错误,但我最终发现了lekksi @移除UITableView单元格前的空白空间发布的这些小细节

扔我的十美分在-我有同样的问题后,我删除了一个标题单元格从表视图。为了解决这个问题,我将属性检查器中的TableView样式从“分组”更改为“普通”,并删除了额外的空间。

我得到了以下的帮助:

YouStoryboard。>属性检查>取消勾选-调整滚动视图嵌入。