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()
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…