Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make UITable header stick to the top of the screen when using Storyboards?

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!

like image 587
Egor Avatar asked Jan 17 '13 10:01

Egor


People also ask

How to make header row stick to the top of screen?

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):

Can you make sticky headers inside a table?

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.

How to create a fixed/sticky header on scroll?

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..

What is sticky header navigation?

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.


1 Answers

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.

like image 123
A-Live Avatar answered Nov 03 '22 00:11

A-Live