Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var refControl = UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()
// Setting up UIRefreshControl
refControl.tintColor = UIColor.white
refControl.addTarget(self, action: #selector(handleRefresh(refreshControl:)), for: UIControl.Event.valueChanged)
tableView.addSubview(refControl)
// Do other things...
}
@objc func handleRefresh(refreshControl: UIRefreshControl) {
DispatchQueue.global().async {
// Fake background loading task
sleep(2)
// Refresh the data here
DispatchQueue.main.async {
self.tableView.reloadData()
refreshControl.endRefreshing()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.