Skip to content

Instantly share code, notes, and snippets.

@jimbrayrcp
Last active May 6, 2020 16:05
Show Gist options
  • Save jimbrayrcp/799b93bdc1268fc93234fff77ed2acf9 to your computer and use it in GitHub Desktop.
Save jimbrayrcp/799b93bdc1268fc93234fff77ed2acf9 to your computer and use it in GitHub Desktop.
pull to refresh UITableVIewController Swift 5: iOS: 13.1
// -------------------------------------------
// Settings: Select the table view controller
// open the attributes inspector, and enable
// refreshing
// Add title color and center
// ****************************
// ADD TO VIEW DID LOAD
// ----------------------------
refreshControl?.addTarget(self, action: #selector(refreshData(_:)), for: .valueChanged)
// ------------- Add Methods ---------------
// include the datasource you are updating
// -----------------------------------------
// MARK: - Pull Refresh
@objc private func refreshData(_ sender: Any) {
configureFetchedResultsController()
do {
try fetchedResultsController.performFetch()
} catch {
print("An error occurred")
}
self.tableView.reloadData()
DispatchQueue.main.async {
self.tableView.refreshControl?.endRefreshing()
}
}
func reload(tableView: UITableView) {
tableView.reloadData()
tableView.layoutIfNeeded()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment