2017-09-26 86 views
2

当我在iOS 11 SDK上更新我的应用程序时,TableView开始表现奇怪,它增加了额外的顶部空间,但实际上额外的空间是Cell本身,但它没有渲染,请通过附加在ios 11更新之前和之后的图像。 谢谢!iOS 11 UITableView的额外顶部空间

this is after ios 11 update

Before ios 11

+4

请分享代码还@lekve –

回答

-3

看来,iOS的11增加梯度层的TableView产生这个问题

+0

请使用您的问题编辑链接添加额外的信息。后回答按钮应该只用于问题的完整答案。 - [来自评论](/ review/low-quality-posts/17652424) – Jolta

+0

这不提供问题的答案。要批评或要求作者澄清,请在其帖子下方留言。 - [来自评论](/ review/low-quality-posts/17652424) – Wez

-2

我们在iOS上的11项目中的保存问题,2种方式是有用的我的项目如下:

1.添加委托方法:

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return [UIView new]; } 

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { return [UIView new]; } 

2.设置的UITableView contentInset:

tableView.contentInset = UIEdgeInsetsMake(-25, 0, 0, 0); 

.TOP值取决于你的UI设计。

+1

嵌入式硬编码是一个可怕的想法。 –

5

我不知道为什么,但当我以编程方式添加表视图发生空间。你需要的是在viewForHeaderInSection

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 
    return UIView() 
} 

返回空视图如果你想零空间,添加它也

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
    return 0.01 
} 

而且,我意识到,错误只出现在Swift4。

15

在代码中设置新属性contentInsetAdjustmentBehavior,它会解决问题。

if #available(iOS 11.0, *) { 
    collectionView.contentInsetAdjustmentBehavior = .never 
} 

上有UIScrollView的偏移

此属性指定的安全区域插图用于修改 滚动的内容区域一个新的属性称为iOS的11加contentInsetAdjustmentBehavior确定调整内容视图。此 属性的默认值是自动的。

+0

把这个放在哪里? –

0

只是发生在iOS上11对我来说,我的解决办法:

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)]; 

OR

self.tableView.tableHeaderView = UIView(frame: CGRect(x:0,y:0,width:0,height:CGFLOAT_MIN))