UITableView Section Header Stay Anchored for All Sections - ios

I have a UITableView with many sections. It is a simple table view. I am using viewForHeaderInSection to create custom views for these headers. So far, so good.
The default scrolling behavior is that when a section is encountered, the section header stays anchored below the Nav bar, until the next section scrolls into view.
My question is this: can I change the default behavior so that the first section header stay anchored at the top for all sections?
Thanks.
Desired Behavior image url:
https://www.dropbox.com/s/2lnspddx02aku1n/scroll.png?dl=0

I've done this by augmenting the header/data relationship. You can have a section header on even numbered sections, and data in odd numbered sections.
Example: For section 0, you can show the appropriate heading, but have 0 rows in that section. The data for section 0 should show up in section 1. Section 1 will not have a header. etc etc.

Related

Shows bottom section of table view at visible view

I know the title is confusing. So I explain what I expect.
I have 3 sections in my table view. The first section has one or more rows. And second and third sections has only one row. When the first section has more than 4 rows the next sections going to be visible by scrolling table view bottom.
But I need these sections be visible in this case.
Actually I need show these sections at the bottom of the visible frame when first section has more than 4 rows!
Is it possible ?
The thing you can do it to display only the 3 first rows of the first section and then when the user starts scrolling, you add the additional cells to the first section while he is scrolling until you've added all of your cell.
Do the opposite when scrolling to top.
You can use two different TableView instead of one.
declare first TableView with only one section & seconds TableView with two section with one row each.
for that you need to use UIViewController instead of UITableViewController.
in this way your bottom TableView Cell always stay visible while first TableView can scroll with more cells.

Is a table view with custom cells still a plain table view?

Apple defines a plain table view like the following:
Plain. In the plain style, rows can be separated into labeled sections
and an optional index can appear vertically along the right edge of
the view. A header can appear before the first item in a section, and
a footer can appear after the last item.
Or in more detail:
A table view in the plain (or regular) style displays rows that
stretch across the screen and have a creamy white background (see
Figure 1-1). A plain table view can have one or more sections,
sections can have one or more rows, and each section can have its own
header or footer title. (A header or footer may also have a custom
view, for instance one containing an image). When the user scrolls
through a section with many rows, the header of the section floats to
the top of the table view and the footer of the section floats to the
bottom.
A variation of plain table views associates an index with sections for
quick navigation; Figure 1-2 shows an example of this kind of table
view, which is called an indexed list. The index runs down the right
edge of the table view. Entries in the index correspond to section
header titles. Touching an item in the index scrolls the table view to
the associated section. For example, the section headings could be
two-letter state abbreviations, and the rows for a section could be
the cities in that state; touching at a certain spot in the index
displays the cities for the selected state. The rows in indexed lists
should not have disclosure indicators or detail disclosure buttons,
because these interfere with the index.
Now you can have custom cells instead of the four default styles (Default, Subtitle, Value 1, Value 2). If you have a "crazy" custom cell is it still a "plain" table view? Or is it only valid for the default styles? Because the docs only shows the default styles on the screenshots.
The tableview style affects the table view — not the table view cells. So yes, a plain tableview can — and should have — custom cells.

How do I float all section header views (or keep all visible) on a UITableView?

I have a UITableView with two sections. I would like the header views for section 0 and section 1 to remain visible at all times regardless of scroll position. How can I accomplish this?
The easiest way. Or quickest way is to add a subview to the view as header 0 (separate to the tableview). Seeing as that is always top. So basically, slap the subview on top.
Then add Header 1 as normal found in
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
What you need to do is set the content inset of the scrollview(subclassed from uitableview) to the height of the subview that you added for header 0.
I can't think of an out-of-the-box (easy) solution. The default behavior only floats the section header(s) of currently visible rows.
I believe the approach would be to define viewForHeaderInSection as array (UICollectionView) of all the section header views before the current section (inclusive).
EDIT: (on second thought)
Can you detail the behavior you are looking? I haven't come across any app that does this. May be, you just need to change the approach to deal with the problem and achieve the same user behavior.
E.g. -
You can show only the section headers (with zero rows in all) and then when user tap one of the section then you insert the rows for that section. In fact, by default you can start with first section with filled in all its rows and when user taps on another section, you close (remove) the previous rows and insert rows in this section.
I had column headers that I wanted to remain visible at all times. I just created them as UIViews and added them as subviews to the view containing my UITableView.
This wasn't the solution I was originally headed for but I settled for it when no other option seemed straight forward.

Making section in UITableView closed(with 0 cells) after scrolling away and returning to it

I have a UITableView where I have section headers that can be tapped to expand or collapse the section. In my particular example each section only has one row, which is either visible (section expanded) or hidden (section collapsed). (I have a UITapGestureRecognizer on the section headers which I use to expand or collapse the sections) here the process of my actions:
I'm tap on the section (this is UITableViewHeaderFooterView custom view) and i see the cell that appears under the section header. At this moment everything is going OK. But when i scrolling down my tableview, cell goes behind header (like in Contacts application , header is first letter of contact). And finally when i scroll enough to don't see that section with that cell on, and when i scroll up - to return to my display that section - i want to make this section automatically known that when i return(from scrolling away that section from view) to it - i want that section already was closed with 0 cells in it.
Maybe i must use -(void) prepareForReuse at my custom UITableViewHeaderFooterView, or scroll methods ? or any tableView methods?
Thank you
You can implement the scroll view delegate methods and use them to check the scroll position (contentOffset) and / or the visible cells (indexPathsForVisibleRows). Once you know that you can collapse any sections that are no longer visible. You should probably use one of the scroll methods that means the scrolling has stopped (maybe scrollViewDidEndScrollingAnimation:) because changing the table view content size (which changing the number of rows will do) during a scroll animation could cause it to stop abruptly.

UITableView sections to always stay within view

I have a UITableView with 3 sections:
section 1:
the header title of this section is "Players" and the cotent is exactly 1 cell containing a horizontal list of 1-4 players names.
section 2:
the header title of this section is "Rounds" and the content is X cells each containing a horizontal list of each respective players score for round X.
section 3:
the header title of this section is "Totals" and the content is exactly 1 cell containing the sum of each player's round scores.
Right now, all these sections scroll as section 2 expands with new rounds, but I want to always keep section 1 at the top of the screen, and have section 3 right below section 2, until it expands down to the bottom of the screen and then stop and stay there.
I guess I could do this with 3 separate table views inside a UIView but that seems kind of convoluted and I section 3 wouldn't stay right below section 2 until it expanded to the bottom of the screen; it would just always be at the bottom...
Is there a way to keep a table section/row always visible, and have the others still scrollable?
Use 3 UITableViews as you discussed, and just animate the position of the Third tableview to move it down each time you add a cell to tableView 2, until it reaches the bottom of the screen then just leave it there. (Also you will need to expand the height of tableView 2 as you add elements to it.)
Otherwise, like Cyrille said, there is no way to implement that with one tableview only.
Not with the standard UITableView implementation, no.

Resources