Last active
May 6, 2020 16:05
-
-
Save jimbrayrcp/799b93bdc1268fc93234fff77ed2acf9 to your computer and use it in GitHub Desktop.
pull to refresh UITableVIewController Swift 5: iOS: 13.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ------------------------------------------- | |
// 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