2016-01-19 29 views
0

我有一個帶過濾按鈕的UITableView。如果按下該按鈕,則可能發生該表是空的。爲了通知用戶,我在這種情況下添加了一個tableheader視圖。如果有行要顯示,我將標題設回零。從UITableView中刪除表頭後,還有一個空缺

更新:我不是在談論節標題,我是在談論表頭。

一切都按預期工作,但如果移除了表頭,我發現表格上有一個空白,但之前沒有。任何想法如何擺脫,如果它?

這是代碼:

if(_sections.count == 0) { 
    UIView *tableHeader = [self getTableHeader]; // make a view 
    self.tableView.tableHeaderView = tableHeader; 
} 
else { 
    self.tableView.tableHeaderView = nil; 
    [self.tableView reloadData]; // I added this as a test - no luck 
} 

這是它過濾了所有一切之前的外觀:

everything crisp and clean, no gap.

這是 「空」 的情況:

all data filtered: Show the message

這是如果我再次取出過濾器:

removed filter again

回答

1

你試過頭高度設置爲0.0f時部分= 0:- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

編輯:
我認爲解決方案你正在尋找替換self.tableView.tableHeaderView = nil;與:self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];發現在Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7由先生T

+0

你建議,該差距實際上是第一節?因爲我沒有更改節標題代碼,所以我添加了一個表標題... – thst

+0

我不完全確定 - 但添加節標題時,我通常確保處理所有情況下的高度。 雖然我可能會誤解,這是表格視圖的頭部還是部分的頭部? – aduflo

+0

它不是節標題,它是表頭。 – thst

相關問題