Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull to refresh UITableView without UITableViewController

I'm trying to implement a pull to refresh feature in a UITableView within a UIViewController. I can't use a UITableViewController because I want the UITableView to be a smaller subview in the view controller, with some other stuff above it. I assume this is possible, but has anyone seen an implementation of it?

like image 566
Daniel Robinson Avatar asked Apr 24 '12 03:04

Daniel Robinson


1 Answers

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() } 
like image 183
Berik Avatar answered Oct 12 '22 22:10

Berik