2014-03-29 51 views
0

我想在UITableView中隱藏第一個區域的標題。因此,我在下面的函數中將高度設置爲0。但標題仍顯示?怎麼了?如果我將它設置爲例如1我在桌子上看到一條小線。有任何想法嗎?在UITabllView中隱藏區域標題

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    if (section == 0) { 
     return 0; 
    } else { 
     return 18; 
    } 
} 
+0

貌似http://stackoverflow.com/questions/1386826/uitableview-not-respecting-heightforheaderinsection-heightforfooterinsection – NathanAldenSr

+0

的重複描述了同樣的問題,但我發現了一個更好的解決方案(見下文)。 – Morpheus78

回答

1

我通過在viewDidLoad()方法中添加下面的代碼行來解決了這個問題。此外,將heightForHeaderInSection中的高度設置爲1.0f(方法參見上文)。

// Correct position because section header height will be set to 1 in order to hide it. 
self.tableView.contentInset = UIEdgeInsetsMake(-1.0f, 0.0f, 0.0f, 0.0); 
+0

整潔!我會記住這一個。 :) – NathanAldenSr