Home > Net >  Refresh Control is not refreshing tableView properly
Refresh Control is not refreshing tableView properly

Time:12-07

I have set up a refresh control but its not working, I did try to reloadData() in tableView , ill provide my code if there is a mistake :(

Its not reloading nothing in tableView

 @objc private func refreshListData(_ sender: Any) {
    self.monitorimiTableView.reloadData()
    self.pullControl.endRefreshing()
}

override func viewDidLoad() {
    super.viewDidLoad()
    pullControl.bounds = CGRect(x: 0, y: 50, width: pullControl.bounds.size.width, height: pullControl.bounds.size.height)
    pullControl.attributedTitle = NSAttributedString(string: "")
    pullControl.addTarget(self, action: #selector(refreshListData(_:)), for: .valueChanged)  
}

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

CodePudding user response:

let refreshControl = UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()
  refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
 refreshControl.addTarget(self, action: #selector(self.refresh(_:)), for: .valueChanged)
 tableView.addSubview(refreshControl) // not required when using UITableViewController
}
@objc func refresh(_ sender: AnyObject) {
 // Code to refresh table view  
refreshControl.endRefreshing()
}
  • Related