UIRefreshControl endRefreshing is not smooth UIRefreshControl endRefreshing is not smooth ios ios

UIRefreshControl endRefreshing is not smooth

I'm adding a new answer since the only one is not very precise in explanation. And this would probably be too much for comments.

The solution by Halpo is correct. But the reason mentioned is wrong.

Calling -[NSObject (NSDelayedPerforming) performSelector:withObject:afterDelay:] guarantees the call to be performed in the next runloop iteration.

So this does not work, because there is a small delay, but you're moving it to the next loop.

Actually you sh/could decrease the delay to 0.0 and it would still work. Also, a more correct (in terms of using the object meant to achieve something, not better in outcome) implementation is possible.

Here are the various code snippets for that:

// SOLUTION I[[self tableView] reloadData];[[self refreshControl] performSelector:@selector(endRefreshing) withObject:nil afterDelay:0.0];// SOLUTION II (semantically correct)[[self tableView] reloadData];[[NSOperationQueue currentQueue] addOperationWithBlock:^{    [[self refreshControl] endRefreshing];}];// SOLUTION III (GCD)dispatch_async(dispatch_get_main_queue(), ^{    [[self refreshControl] endRefreshing];}];


As johann-fradj pointed out, you could also use GCD. I do like GCD a lot, but I think, solution II is most descriptive about whats going on. Also, GCD is not very Objective-C-ish, so I'd personally rather stick to my solution.

Fixed the problem - I added a tiny delay to endRefresh after reloading data:

[self.tableView reloadData];[self.refreshControl performSelector:@selector(endRefreshing) withObject:nil afterDelay:0.05];

Swift 4 solution

    tableView.reloadData()    if refreshControl?.isRefreshing == true {        DispatchQueue.main.async {            self.refreshControl?.endRefreshing()        }    }

Other solutions (delay, using CATransaction, ...) are more complex and don't give any visible advantage