Rohan Sharma
Rohan Sharma

Reputation: 1

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

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

Upvotes: 0

Views: 1211

Answers (2)

kaushal
kaushal

Reputation: 1573

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

Upvotes: 0

aafat
aafat

Reputation: 148

Please try this code. Collection view lost our height.

self.colView.alwaysBounceVertical = YES;

Upvotes: 9

Related Questions