section header for UICollectionView - iphone

I'm subclassing UICollectionViewLayout.
UITableView sectionHeader stays around when scrolled down.
(You can see this when you scroll down the contacts list, section header(A, B, C..) stays around until next section header takes its place.
I'd like to add a section header to my UICollectionView but don't know how to do this.

Related

Swift: UITableView scrolls back to top when section header height is changed dynamically

!
I have a tableView with a single section. The header of this section holds the Sort By label and the three ImageViews. The view below it is a UITableViewCell.
The first image shows the initial view of the section header. When the header is clicked (have added a tap gesture), I expand the section view by changing the constant of the height constraint programmatically (have created an outlet for the height constraint).
Everything works fine, the section header expands as desired. However the tableviewcell scrolls right to the top again. Meaning, if when the section header was not expanded and I had scrolled down to some level, as soon as the header view expands, the entire offset is lost and tableviewcell scrolls right back to the top. I do not want this. I want the table view cell to remain where it is and for the section header to expand and collapse over it. How can I achieve this? Please help.
it sounds like you might be doing this:
setContentOffset(CGPointZero, animated: true)
which you shouldn't do.

Scroll outer tableview with inner tableview and vice versa when headerview reaches top

I realize variations of this question have been asked, but I'm having trouble connecting the dots into a coherent solution for my problem. So here's my scenario:
I have a UITableView that has 2 sections. Section 1 has no header view, and 1 cell. Section 2 has a header view (it floats as is the default behavior with plain table views), and 1 cell. This solitary section 1 cell has a horizontally paging scrollview with 3 pages. Each page is a tableview. This sounds a little nutty, but it is totally legal and makes perfect sense. My scenario is a user profile screen. Section 1's cell is the user's bio. Section 2's header is a paging menu that shows the three menu options. The pager has three tableviews for all the content a user publishes, follows, and their posts.
The problem is that when the user scrolls any of the inner tableviews in the pager, I want the outer tableview to scroll until the bio is scrolled off screen and the section header hits the nav bar of the view controller. And then I want the inner scrollview to take over the scrolling.
I've been playing with a combination of the UIGestureRecognizerDelegate methods: shouldRecognizeSimultaneouslyWithGestureRecognizer & shouldRequireFailureOfGestureRecognizer. I am able to either scroll the tableviews simultaneously (which, btw, isn't terrible, but it's definitely not my desired behavior) or just enable scrolling on either the inner or outer tableview. I would love to be able to solve this problem using the UIGestureRecognizerDelegate because my gut tells me that the solution doesn't need to involve any delegation and overriding contentOffsets using UIScrollViewDelegate methods like scrollViewDidScroll: and so on. But maybe I'm wrong, and I will have to go that route.
Thought I'd throw this up there before I threw in the towel. Would appreciate any help!

UITableView section appears over tableHeaderView

I have a UITableView instance to which I have added a header using the tableHeaderView property. I observe for changes in the contentOffset property to be able to move the header in the opposite direction, allowing it to stay at the top of the table when scrolled at least a certain amount.
I want to have it in this way because of two reasons. First, I want the scroll bar to cover the header. Secondly, I'm moving the header with the scrolled content for about 100 points, then I'm keeping it at the top.
Everything is fine except for one detail. The table view sections appear above the tableHeaderView. How do I get them to appear below?
EDIT: How do I get the sections of a UITableView to appear below the assigned tableHeaderView view in the view stack?
This is not a solution to the problem, but this way worked for me:
I simply pushed the titles into the array feeding the table view cells as strings and added them as cells with different cell identifiers than the cells i used otherwise.

How can I make the first and last UITableView cells stay on screen when scrolling?

I have noticed in the iTunesConnect iOS app, the first and last cells of the grouped UITableView stay on screen even though the other cells are scrolling through them. They also move with the tableview. For example when scrolling to the bottom of the table (moving up), the last cell moves up with the table as it leaves the bottom of its position on screen.
Does anyone have an example of how this could be done? I have tried setting the header and footer views but these scroll off screen when moving the tableView.
Thanks.
I think the best approach would be to use a plain UITableView with Header and Footer set, and "skin"/theme your custom UITableViewCells to look like grouped UITableViewCells.
you'd might want to have a look over here for some pointers on how to achieve this.

Why don't the header views that are returned from viewForHeaderInSection scroll with the rest of the table?

I just implemented the UITableViewDelegate::viewForHeaderInSection method to return a custom view. However, when I run the app and load the table view, I notice that header view remains stationary while the rest of the table cells scroll underneath it. What gives? How do I get it to scroll with the rest of the table?
Thanks for your wisdom!
That's how it's meant to work. The header for a section will stay at the top of the tableview to give the user a sense of which section she is currently in. Then when she scrolls further down into the second section, that section header scrolls into view and then eventually replaces the first section header at the top.
You can see this in the Contacts app on your phone.