iosobjective-cuitableviewuirefreshcontrol

How do I make the refresh action occur after the touch is released from the refresh control?


I am implementing UIRefreshControl on a UITableView to refresh the table's data. On other pull-to-refresh implementations, the refresh process does not begin until the user's finger is lifted while in the pull's refresh distance. UIRefreshControl does not immediately seem like it has this customization.

My UIRefreshControl init code:

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

My refresh: code is fairly basic:

- (void)refresh:(id)sender {
    // Refresh code...
    [sender endRefreshing];
}

How can I delay the refresh: function until the user removes their finger from the pull?


Solution

  • I've also stuck with the same problem. I don't think that my approach is very nice, but seems like it works.

    1. Init UIRefreshControl

      UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
      self.refreshControl = refreshControl;
      
    2. Check state of UIRefreshControl when user finish dragging the table (UITableViewDelegate conforms to UIScrollViewDelegate)

      - (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView
      {    
          if( self.refreshControl.isRefreshing )
              [self refresh];
      }
      
    3. Update table

      - (void)refresh
      {
          [self.refreshControl endRefreshing];
      
          // TODO: Update here your items
      
          [self.tableView reloadData];
      }
      

    Hope it will help you.