I have a UITableView
with a header. the problem I currently have is that the header doesn\'t scroll with the table. I need it to scroll off screen (above) when the
Changing the UITableViewStyle
from Plain
to Grouped
make the section header to scroll with the other cells.
create sectionHeader view in a new method and then add to the end:
self.tableView.tableHeaderView = sectionHeader;
if you have dynamic header view or single view select table style
If you write tableView.tableHeaderView = sectionHeader
you will lose the actual table view header.
If you want to have table view header along with section headers you have to set UITableViewStyle
property to UITableViewStyleGrouped
.
Also if you want to calculate section header height automatically you can return UITableViewAutomaticDimension
in heightForHeaderInSection
method like this:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return UITableViewAutomaticDimension;
}
That behavior is only common when the UITableViewStyle
property of the table is set to UITableViewStylePlain
. If you have it set to UITableViewStyleGrouped
, the headers will scroll up with the cells.
This answer is taken from this question.
This solution works regardless of the number of headers.
If you have a single header in the table then you can use tableHeaderView
as below:
tableView.tableHeaderView = Header;
Or if you have multiple header in table than you need to use Group table instead of plain table.
Thanks