Skip to content

Instantly share code, notes, and snippets.

@e23z
Created July 26, 2017 13:04
Show Gist options
  • Select an option

  • Save e23z/c984b19b640b29d2e6057a893d85bf70 to your computer and use it in GitHub Desktop.

Select an option

Save e23z/c984b19b640b29d2e6057a893d85bf70 to your computer and use it in GitHub Desktop.
[Pull to Refresh (UIRefreshControl)] How to add "pull to refresh" to a table view in iOS. #mobile #swift #ios #ui #ux
var refreshControl: UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
tableView.addSubview(refreshControl) // not required when using UITableViewController
}
func refresh(sender:AnyObject) {
// Code to refresh table view
}
// then at some point
refreshControl.endRefreshing()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment