We have implemented pull down to refresh on our UITableViewController. For a long running refresh if the user goes to the home screen and then returns to the app the UIRefreshControl appears to be stuck - it is still displayed but isn't spinning. Have tried a number of solutions on SO but nothing has worked.
Our implementation:
//Configure pull to refresh when user "pulls down"
self.refreshControl?.addTarget(self, action: #selector(NotificationTableViewController.handleRefresh(refreshControl:)), for: UIControlEvents.valueChanged)
//In handleRefresh we will explicitly start the refresh control if this is a background refresh and not a user initiated pull to refresh
refreshControl.beginRefreshing()
self.tableView.setContentOffset(CGPoint(x: 0, y: -refreshControl.frame.size.height - self.topLayoutGuide.length), animated: true)
//Then once we have reloaded data we stop the refresh in the same manner for user initiated or background refresh (done on main thread)
refreshControl.endRefreshing()
Solutions we've tried:
Restarting the refreshing when entering foreground when currently refreshing:
if refreshControl!.isRefreshing == true {
refreshControl!.endRefreshing()
refreshControl!.beginRefreshing()
self.tableView.setContentOffset(CGPoint(x: 0, y: - refreshControl!.frame.size.height - self.topLayoutGuide.length), animated: true)
}
... Then the following solutions are about ending the refreshing if we are not supposed to be refreshing. I did try them but in our case we are supposed to be refreshing...
Calling endRefreshing()
when entering foreground if not refreshing:
if refreshControl?.isRefreshing == false {
refreshControl?.endRefreshing()
}
Sending the refresh control to the back on entering foreground:
self.refreshControl?.superview?.sendSubview(toBack: self.refreshControl!)
Does anyone have a fix that works on iOS 10?