Pull to refresh UITableView without UITableViewController

前端 未结 6 685
借酒劲吻你
借酒劲吻你 2020-11-29 15:11

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 sm

6条回答
  •  余生分开走
    2020-11-29 15:46

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

提交回复
热议问题