Skip to content

Instantly share code, notes, and snippets.

@jamesgathu
Last active June 12, 2018 10:18
Show Gist options
  • Save jamesgathu/978b36622dad985b81824444a9705811 to your computer and use it in GitHub Desktop.
Save jamesgathu/978b36622dad985b81824444a9705811 to your computer and use it in GitHub Desktop.
To add pull to refresh on a TableView

Adding Pull to Refresh To iOS tableView

Follow the code below for adding pull to refresh to a tableview

          value       
iOS version 11.2
Swift 4
var refresher : UIRefreshControl!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
refresher = UIRefreshControl()
// to add text shown below the refresh indicator
refresher.attributedTitle = NSAttributedString(string : "showing below wheel")
refresher.addTarget(self, action: #selector(self.reloadData), for: UIControlEvents.valueChanged)
tableView.addSubview(refresher)
}
@objc func reloadData(){
//some asynchronous | synchronous task to load data
...
//on completing the task
if refresher.isRefreshing {
refresher.endRefreshing()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment