Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIRefreshControl - How do I make the refresh action occur after the touch is released?

Long time listener, first time caller here on stack overflow. Be gentle.

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?

like image 677
outphase Avatar asked Mar 23 '13 06:03

outphase


1 Answers

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.

like image 136
Ned Avatar answered Oct 01 '22 17:10

Ned