5

I was wondering if there was any way to allow the tableview header of a plain table to scroll with the table?

I am currently using the following method to add my header.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Zhen
  • 12,361
  • 38
  • 122
  • 199

2 Answers2

18

Actually the tableHeaderView scrolls with table. This is not the case for section header views. If you have only one section then you can have the header view as tableHeaderView.

table.tableHeaderView = aUiView;

If you have more than one sections and all of them have their own header views, then you have no choice than leaving the header views behave in their own ways. Or, you can imitate the header view by making/configuring/customizing the first row of each section look like header view and remove the actual section header views.

EmptyStack
  • 51,274
  • 23
  • 147
  • 178
  • I see. Is that a delegate method to set the tableHeaderView or I just directly set it for the table.tableHeaderView = aUiView, where aUIView is the header view i need? Also how do I set the height of the tableheadervview in this case. – Zhen Sep 20 '11 at 10:54
  • 2
    You can directly set the tableHeaderView as a property. Table header will take the height of the view you assign. No need to set the height for tableHeaderView explicitly. – EmptyStack Sep 20 '11 at 10:57
0

Just use this one self.tableView.tableHeaderView = sectionHeader;

Ash
  • 5,525
  • 1
  • 40
  • 34