[应用程序]选项卡使用刷新按钮更新列表,效果很好。尝试使用“下拉以刷新”,但根本不起作用。
protocol StaffHistoryDelegate: class {
func updateList()
}
class StaffHistoryController: UIViewController {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var activityLoad: UIActivityIndicatorView!
let myRefreshControl: UIRefreshControl = {
let refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: " ")
refreshControl.addTarget(self, action: #selector(refresh(sender:)), for: .valueChanged)
return refreshControl
}()
override func viewDidLoad() {
super.viewDidLoad()
prepareSearch()
delegateStaffHystory = self
do { try self.frc.performFetch() }
catch {}
tableView.refreshControl = myRefreshControl
}
@IBAction func btnRefreshPressed(_ sender: UIBarButtonItem) {
loadingShow(text: " ")
delegateTabController?.loadStaffBill(completion: { (error) in
DispatchQueue.main.async {
loadingHide()
if error != nil {
let alert = getAlert(title: error?.localizedDescription, message: nil)
self.present(alert, animated: true, completion: nil)
}
}
})
}
@objc private func refresh(sender: UIRefreshControl) {
updateList()
tableView.reloadData()
sender.endRefreshing()
}
[不幸的是我不是编码员,我真的很难理解该做什么。 (我设法在其他2个选项卡上实现了“下拉刷新”,但该选项卡的编码方式不同)。
我假设'updateList()'是刷新数据的函数-
@objc private func refresh(sender: UIRefreshControl) {
updateList()
tableView.reloadData()
sender.endRefreshing()
}
在函数完成计算之前,请检查tableView是否正在重新加载数据。在'updateList'函数中刷新数据时,尝试添加以下行。
tableView.reloadData()