2017-09-26 88 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))