thekevinscott
thekevinscott

Reputation: 5413

UITableViewController pull to refresh with a frozen header

I have a mockup that looks like this:

mockup1

This is all one big Table Controller that you can scroll.

When the section header hits the top of the page it freezes along the top, like so:

mockup2

Which is working fine. However, when you go back to the top and do a pull to refresh, I want it to do this:

enter image description here

So the pull to refresh dialog appears between the top table header cell and the section header (that is no longer frozen).

Is this possible? I haven't found an implementation like this in my searches.

Upvotes: 4

Views: 1552

Answers (1)

iDev
iDev

Reputation: 23278

You can do the following to achieve this,

  1. Add a UIScrollView as the subview of UIViewController's view.
  2. Add a UIView and UITableView as the subview of this scroll view
  3. UIView inside scroll view represents table header cell.
  4. Section header can be the header of UITableview and table contents represents the UITableView's cells.
  5. Add UIRefreshControl as subview of UITableView and set its target method.
  6. Implement the scrollview delegate - (void)scrollViewDidScroll:(UIScrollView *)scrollView for both UITableview and UIScrollview.
  7. When you are scrolling the tableview, move the parent scrollview whenever the table view header moves in the upward direction till the header reaches the top. Add an if condition in scrollview delegate to check for this.
  8. When the table view is moved the downward direction, move the parent scrollview until the UIView table cell header is visible after this stop scrolling of UIScrollview and allow table view to scroll. This will enable the UIRefreshControl.

Here the key thing is the - (void)scrollViewDidScroll:(UIScrollView *)scrollView method and how you implement the scrolling. You can add a check for contentOffset to determine how much tableview and scrollview has been scrolled. In order to restrict the scrolling you can manually set this value in this delegate method to a particular value and it wont scroll after that.

Upvotes: 1

Related Questions