4

I am using pull to refresh for usual data refresh on a tableview.

Here is my code

-(void)addUIRefreshControl{

    //Instantiate and Configure Refresh Control

    self.refreshControl = [[UIRefreshControl alloc] init]; // initialize refresh control
    self.refreshControl.tintColor = [UIColor appBaseColor]; // set tint color
    [self.refreshControl addTarget:self
                            action:@selector(refreshAPI)
                  forControlEvents:UIControlEventValueChanged]; // add target

    [self.tableView addSubview:self.refreshControl]; // add the refresh control

}

-(void)refreshAPI{

    if ([APP_DELEGATE isNetAvailable]) {
        [self fetchAPI];
    }else{
        if (self.refreshControl) {
            [self.refreshControl endRefreshing]; //end refreshing
        }
    }
}

Everything works fine on iOS Devices & Simulator except for iPhone X. Can anyone suggest what am I doing wrong?

Thanks

Syscall
  • 19,327
  • 10
  • 37
  • 52

1 Answers1

0

Is your app iOS 10 & newer only? If so, you should be using your commented out line:

- (void)addUIRefreshControl{
    UIRefreshControl * refreshControl = [[UIRefreshControl alloc] init]; // initialize refresh control
    refreshControl.tintColor = [UIColor appBaseColor]; // set tint color
    refreshControl addTarget:self
                      action:@selector(refreshAPI)
            forControlEvents:UIControlEventValueChanged]; // add target
    if (self.tableView != NULL) {
        // tableView will have a strong reference (and retain) refreshControl ; no need to have it be its own property
        self.tableView.refreshControl = refreshControl
    } else {
        NSLog(@"suprise!  self.tableView is null");
    }
}

And you should always call "endRefreshing" when the value changes (or updates). Before, you were calling only if isNetAvailable was false.

-(void)refreshAPI{

    if ([APP_DELEGATE isNetAvailable]) {
        [self fetchAPI];
    }

    [self.tableView.refreshControl endRefreshing]; //end refreshing
}
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215