pull to refresh not working in collection view when collection view have no data in ios

1.2k Views Asked by At

This is my refresh control in worldview method.

    self.colView.refreshControl = [[UIRefreshControl alloc] init];
    self.colView.refreshControl.backgroundColor = [UIColor purpleColor];
    self.colView.refreshControl.tintColor = [UIColor whiteColor];
    [self.colView.refreshControl addTarget:self
                    action:@selector(refresh)
                  forControlEvents:UIControlEventValueChanged];
2

There are 2 best solutions below

2
aafat On

Please try this code. Collection view lost our height.

self.colView.alwaysBounceVertical = YES;
0
kaushal On

Your code looks fine, Just you have to move tableview at top and set some frame before adding it to collectionview. This will work even if your collection view content view have 0 frame size:

 -(void)addPullToRefressToTableView {

    UIView *refreshView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, 0, 0)];
    [self.tableView insertSubview:refreshView atIndex:0];

    UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
    refreshControl.tintColor = [UIColor grayColor];
    [refreshControl addTarget:self action:@selector(reloadDatas) forControlEvents:UIControlEventValueChanged];
    NSMutableAttributedString *refreshString = [[NSMutableAttributedString alloc] initWithString:@"Pull To Refresh"];
   [refreshView addSubview:refreshControl];
}