2014-03-29 52 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