I've made header using this post: Table Header Views in StoryBoards
But i am unable to make header stick (fix) to the top of the screen while scrolling.
How can that be achieved?
P.S. Table style is plain, and when i tired to overload viewForHeaderInSection
and returned outlet for header view, it just got worse.
Thanks in advance!
Then let’s take a look at how you can make the header row or a column stick to the top of the screen (or on the left hand side in case of a column). The function in Excel is called ‘Freeze Panes’. Freezing panes helps and keeps the important header row (s) always on top (the numbers are corresponding to the picture on the right hand side):
You can’t position: sticky; a <thead>. Nor a <tr>. But you can sticky a <th>, which means you can make sticky headers inside a regular ol’ <table>. This is tricky stuff, because if you didn’t know this weird quirk, it would be hard to blame you.
Learn how to create a fixed/sticky header on scroll with CSS and JavaScript. Scroll down to see the sticky effect. The header will stick to the top when you reach its scroll position. Scroll back up to remove the sticky effect. Some text to enable scrolling..
When your header is sticky, no matter how long your page is, or how many times you scroll up and down, the nav will be “stuck” to the top of the web page. Some reasons to use sticky header are: So, in this tutorial of HTML fixed header, we will look easy way to make a sticky header navigation.
Here's the code which I believe makes the header view stick to the table top (that is not it's default behavior):
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect rect = self.tableHeaderView.frame;
rect.origin.y = MIN(0, self.tableView.contentOffset.y);
self.tableHeaderView.frame = rect;
}
An alternative is to have header view for the first section. You can't use any subview at viewForHeaderInSection
, you have to return there the view which is not yet at views hierarchy. The advantage of the method is that the section header view is designed to be at the table top, the drawback is that you might want to have headers for sections in the feature, it will break the solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With