Ahd Radwan
Ahd Radwan

Reputation: 1100

UIRefreshControl is not working in collection view

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?

Upvotes: 0

Views: 1458

Answers (5)

Jayesh Thanki
Jayesh Thanki

Reputation: 2077

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

Upvotes: 2

Dinesh
Dinesh

Reputation: 1137

#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];
    }

}

Upvotes: 0

iOS77
iOS77

Reputation: 522

Here is an example of a UIRefreshControl.

UIRefreshControl *control = [[UIRefreshControl alloc] initWithFrame:CGRectZero];
control.tintColor = someColor;
[control sizeToFit];
[tableView addSubview:control];

Upvotes: 0

bunnyshell
bunnyshell

Reputation: 253

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.

Upvotes: 0

Chetan
Chetan

Reputation: 2124

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];
}

Upvotes: 0

Related Questions