Morpheus78
Morpheus78

Reputation: 900

Hide section header in UITabllView

I'd like to hide the head of the first section in a UITableView. Therefore, I set the height to 0 in the following function. But the Header is still shown? What's wrong? If I set it to e.g. 1 I see a small line on top of the table. Any ideas?

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

Upvotes: 0

Views: 171

Answers (1)

Morpheus78
Morpheus78

Reputation: 900

I solved this issue by adding the following line of code in the viewDidLoad() method. Additionally set the height in the heightForHeaderInSection to 1.0f (method see above).

// 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);

Upvotes: 1

Related Questions