0

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()

}
Matt
  • 315
  • 2
  • 6
  • 20
  • Please [edit] your question and include the complete error message. You left off the most important part of the error. – rmaddy Sep 11 '18 at 19:01

1 Answers1

0

I solved by adding @objc before method implementation in ViewController.swift. No other changes needed.

// Pull to refresh implementation
@objc func pullToRefresh() {

    // some action
    self.pullToRefreshEnd()
}
Matt
  • 315
  • 2
  • 6
  • 20