I'm trying to add an extension to add pull to refresh to Table View. This is the reference answer which I'm following https://stackoverflow.com/a/33255722/6307359
My code throws error "unrecognized selector sent to instance"
Following is my code. Can anyone please look into it and let me know where I'm doing it wrong?
Tx in advance.
Extension.swift
var refreshControl = UIRefreshControl()
public extension UIViewController
{
func addPullToRefresh(tableView: UITableView, refreshMethodName: String){
refreshControl.addTarget(self, action: Selector(refreshMethodName), for: .valueChanged)
if #available(iOS 10.0, *) {
tableView.refreshControl = refreshControl
} else {
tableView.addSubview(refreshControl)
}
}
func pullToRefreshEnd (){
refreshControl.endRefreshing()
}
}
ViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
self.addPullToRefresh(tableView: statementsTable, refreshMethodName: "pullToRefresh")
}
// Pull to refresh implementation
func pullToRefresh() {
// some action here
self.pullToRefreshEnd()
}