While in the Interface Builder, it’s pretty easy to add an UIView to an UITable and show it correctly, just drag and drop and it’s done. But now that’s gonna be optional, so it has to be placed programmatically.
Here’s how it looked like in the interface builder:

When I added the new view as a subview, it showed on top of the UITableView-content, but the content should have some offset. I tried it with the following code:
self.scrollView.frame = CGRectMake(0, -140, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
[self.tableView addSubview:self.scrollView];
[self.tableView setContentInset:UIEdgeInsetsMake(140,0,0,0)];
[self.tableView setContentOffset:CGPointMake(0, -140) animated:NO];
That seemed to work, it shows correctly.. But when I scroll down, the section header stays at 140 pixels from the top. So I guess I’m using the wrong approach, but have absolutely no idea how to fix it. Could anyone give me a push in the right direction?
Okay, I feel really stupid. After hours of trying, I thought of something.. Just checked the source of the .xib file and compared the one with the subview with the one without. The following things showed up:
UIViewwas part a subview of theUITableView.<reference key="IBUITableHeaderView" ref="204195654"/>.So, changed the code to this:
And it works!