UITableView: anchor section header - ios

I have a UITableView with one section and a header. The problem is that when I scroll down beyond the contents of the table, the header is pulled down along with the cells. I would like it to stay at the top of the view. I tried the suggestion on this post,
Change Default Scrolling Behavior of UITableView Section Header
using the footer of a zero-row section as the header, but it still isn't anchored. Does anyone know how to do this properly?

Are you using a UITableViewController? If you are using a UIViewController that contains a UITableView you could just add a UIView above the UITableView.
You could also add the UIView on top of the UITableView and add an alpha gradient to make it look more similar to a regular UITableView section header.

Related

How to make header only stick on negative content offset - Swift

I have a tableView and I have a UIView as the tableView header. I want the header to move up the screen when I scroll down and act just like any normal cell. But when I have reached the top of the view, where if I scroll up it will just bounce back, I want the tableView header to stick to the top.
One example is like the Facebook app headers. They scroll when you scroll, but if you're at the top of the page and you scroll up, they wont scroll down, they stay stuck to the top.
How do I achieve this?
If you're using a normal tableView (not grouped style) and you only have one section, you can accomplish this by using the section header instead. The default behaviour of this type of tableView is as you described. You'll just have to provide a custom view for the section header that looks like your cell.
If this isn't a possibility, you'll need to take advantage of tableView being a subclass of scrollView, and implement the scrollViewDidScroll delegate method to check content offsets etc.

How to make TableView Header Static/ unScrollable

I am working on Table View. I have implemented Header at the top of TableView. Its scrolling when i scroll TableView. Any Solution to make the Header Static.
If you want a static header, it means that it should not be a header. The behaviour of a header is to scroll with the UITableView.
You can replace it with an UIView placed above your UITableView.
Also, you can use the UITableView.headerView (UIView?), this is a view placed at the top end of the whole tableView and not per section as the sectionHeaderView.
You can simply add UIView On top of UITableView.
Like this :
And result will be:

How to make section header anchor to the top of a multi section tableview?

I know if set the tableView's type to "Plain" , the section header will automatically anchor on the top of the tableView. but if I have multi sections in the tableView. When the tableView scroll to the next section ,the first section's header will disappear. I hope the first section's header can always anchor on the tableView's top whatever I scroll the tableview to any section. is there any way to do that?
What you describe does not happen for UITableViewStyleGrouped but for UITableViewStylePlain.
I can't really think of any easy way to do what you want - I suspect you'll have to insert your own subview and manage its position according to the table's scrolling position.
I found this article which might have some good ideas for what you're trying to do.

Recreate this view from overcast

I love overcast and am getting into iOS development. I see this style of screen a lot.
From what I gather this is a table view with cells and then headers but how is the part at the bottom added in and also the subtitle pieces of text below each row.
I can't seem to find a way in storyboard to do this.
You can drag a UIView object into your UITableView instance in Interface Builder and then configure it the way that you want to.
When you drag a UIView into your UITableView, just drag it to the top, just above the top-most UITableViewCell in your UITableView to create a header. To create a footer, just drag it below the intended UITableViewCell. You can then resize the view and lay it out to your content.
Also, if you would like to do it programmatically, have a look at the UITableViewHeaderFooterView.
You can also create header views and footer views for sections by implementing methods of the UITableViewDelegate protocol such as: tableView:viewForHeaderInSection: and tableView:viewForFooterInSection:.

UITableViewController Rows scrolls behind the Header cells?

I have a UITableView with Headers and Rows. When the Rows scroll up into the Header section it looks like they scroll behind the Header. This is fine except I want both my Header and Rows to have non opaque alpha. The design is translucent. When this is the case you can see the Row scroll behind the Header which is bad. Ideally the row just disappears when it scrolls into the Header section.
Anyone have a solution that will still allow me to use translucent Headers? Thanks!
I had the same issue.
If you only have one header the easy solution I did was to just take the header label out of the tableview and put it in the parent view of the uitableview and just shift the uitableview to compensate for the new header view. Now make the header view transparent and the rows don't scroll behind the header view because it is in a different. The downside is that when you scroll up the header doesn't float above the next cell and obviously it doesn't work for multiple headers. Hope this helps.

Resources