在UITableView中隐藏节标题

时间:2014-03-29 21:40:07

标签: ios uitableview ios7.1

我想在UITableView中隐藏第一部分的头部。因此,我在以下函数中将高度设置为0。但是标题仍在显示?怎么了?如果我将它设置为例如1我在桌子顶部看到一条小线。有什么想法吗?

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

1 个答案:

答案 0 :(得分: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);