Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Refresh Control is not refreshing tableView properly

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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()
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading