Search code examples
iosuitableviewuirefreshcontrol

UIRefreshControl is not hiding after refresh. iOS


I am using UIRefreshControl in my table view. I have initiated refresh control in viewDidLoad:

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

I have a target method for scrolling:

-(void) handleRefresh:(UIRefreshControl *) refreshControl{
    [self performSelector:@selector(updateDealsList) withObject:nil withObject:nil];
}

updateDealsList method:

- (void) updateDealsList {
    self.dealsService = [[BestDealsService alloc] initServiceWithDelegate:self isLocalCall:NO];
    [self.dealsService fetchBestDeals];
}

In my service response method:

    [self.refreshControl endRefreshing];
    self.isTableViewInRefreshMode = YES;
    [self.bestDealsTableView reloadData];

Now, I have two issues: 1. My refresh Control is not hiding on success response from my service. 2. If I pull table view down, I can see a refresh control, but if I scroll down again, I see a new one below the previous one.

Image for first refresh control:

enter image description here

Here, after scrolling down again:

enter image description here Note: I am using custom TableViewCell


Solution

  • This is how I fixed it:

    // Pull To Refresh Code
    if(self.refreshControl == nil){
        UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
        [refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
        self.refreshControl = refreshControl;
    }
    [self.myTableView addSubview:self.refreshControl];