【问题标题】:Hide section header in UITabllView在 UITableView 中隐藏部分标题
【发布时间】:2014-03-29 21:40:07
【问题描述】:

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

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

【问题讨论】:

标签: ios uitableview ios7.1


【解决方案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);

【讨论】:

  • 整洁!我会记住这个的。 :)