0

I have added a UIRefreshControl to my collection view:

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

- (void)refreshCV:(UIRefreshControl *)refresh{ 
      NSLog(@"Refresh");
      [refresh endRefreshing];
}

But it is not working always. In other words, sometimes when pulling down it is doesn't call the refresh function. How to solve this?

Muhammad Adnan
  • 2,660
  • 13
  • 25
Ahd Radwan
  • 1,062
  • 3
  • 12
  • 29

5 Answers5

2

Try this answer. You have to set alwaysBounceVertical property of collection view.

Jayesh Thanki
  • 1,879
  • 2
  • 21
  • 29
0
#pragma mark UIRefreshControl

- (void) setUpRefreshControl {
    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];

    //add UIRefreshControl to Collection view
    [self.collectionView addSubview:refreshControl];
}

- (void)refresh:(id)sender 
{
    UIRefreshControl *refreshControl = (UIRefreshControl *)sender;

    // End the refreshing
    if (refreshControl) {
        [refreshControl endRefreshing];
    }

}
Dinesh
  • 1,077
  • 8
  • 14
0

If you are not using UITableViewController class, then do as below

UITableViewController *tableViewController = [[UITableViewController alloc] init];
tableViewController.tableView = self.myTableView;
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self action:@selector(refreshTV:) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = self.refreshControl;

- (void)refreshTV:(UIRefreshControl *)refresh{ 
      NSLog(@"Refresh");
      [refresh endRefreshing];
}
Chetan
  • 1,676
  • 1
  • 11
  • 19
0

Here is an example of a UIRefreshControl.

UIRefreshControl *control = [[UIRefreshControl alloc] initWithFrame:CGRectZero];
control.tintColor = someColor;
[control sizeToFit];
[tableView addSubview:control];
Uma Madhavi
  • 4,601
  • 5
  • 34
  • 70
iOS77
  • 492
  • 5
  • 3
0

You add refreshCV as the target function for refresh control while you actually have refreshTV below. Please check to make sure which function you want indeed.

bunnyshell
  • 233
  • 4
  • 12