Pull to refresh UITableView without UITableViewController

Add a refresh control directly to a UITableView without using a UITableViewController:

override func viewDidLoad() {
    super.viewDidLoad()
    let refreshControl = UIRefreshControl()
    refreshControl.addTarget(self, action: #selector(refresh(_:)), for: .valueChanged)

    if #available(iOS 10.0, *) {
        tableView.refreshControl = refreshControl
    } else {
        tableView.backgroundView = refreshControl
    }
}

@objc func refresh(_ refreshControl: UIRefreshControl) {
    // Do your job, when done:
    refreshControl.endRefreshing()
}

Leave a Comment