I am trying to implement pull to reload for my UITableViewController
in swift here is my code:
class PublicTableViewController: UITableViewController{
override func viewDidLoad(){
super.viewDidLoad()
...
self.refreshControl?.addTarget(self, action: #selector(PublicTableViewController.handleRefresh(_:)), for: UIControl.Event.valueChanged)
}
func handleRefresh(refreshControl: UIRefreshControl) {
self.tableView.reloadData()
refreshControl.endRefreshing()
}
...
}
But when I build this I get the error that Type 'PublicTableViewController' has no member 'handleRefresh'' and I do not understand why.
change like this.
class PublicTableViewController: UITableViewController{
override func viewDidLoad(){
super.viewDidLoad()
...
self.refreshControl?.addTarget(self, action: #selector(self.handleRefresh()), for: UIControl.Event.valueChanged)
}
@objc func handleRefresh() {
self.tableView.reloadData()
}
}
you must add @objc to a method sing to adopt #selector.