6

You can add UIRefreshControl to UICollectionView (or any UIScrollView for that matter) by adding it to collection's subviews:

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[self.collectionView addSubview:refreshControl];

This doesn't work when collection view layout has UICollectionViewScrollDirectionHorizontal.

I tried overriding layoutSubviews to put refresh control to the left, but it wouldn't track scrolling progress this way. Can I trick it into working with horizontal layouts?

Community
  • 1
  • 1
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
  • 1
    Maybe I'm being conservative but although you can add this view in that way, and get it to work, I don't think it was designed for that, the documentation does clearly link it to UITableView. – Daniel Dec 10 '12 at 23:23
  • @Daniel While this is true, I'm seeing a lot of people here doing it this way which makes me feel Apple is likely to make this de facto working behavior official. I also haven't seen a single post saying their app was rejected for using `UIRefreshControl` without a table view. – Dan Abramov Dec 10 '12 at 23:30

2 Answers2

7

I couldn't find any existing solutions so I extended ODRefreshControl with horizontal layout support:

enter image description here

I needed solution in MonoTouch (C#) so I started by source-porting ODRefreshControl and then patched it to work with horizontal layout.

Full C# source code is here, it should be straightforward to port it back to Objective C.
All I did was add an utility function and some conditions here and there.

Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
1

you can achieve this by implementing the UIScrollViewDelegate method

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
     CGPoint offset = scrollView.contentOffset;
     CGRect bounds = scrollView.bounds;
     CGSize size = scrollView.contentSize;
     UIEdgeInsets inset = scrollView.contentInset;
     float y = offset.x + bounds.size.width - inset.right;
     float h = size.width;


    float reload_distance = 75; //distance for which you want to load more
    if(y > h + reload_distance) {
       // write your code getting the more data
       NSLog(@"load more rows");

    }
}
Nitin
  • 1,383
  • 10
  • 19