Skip to content

Instantly share code, notes, and snippets.

@garrettmurray
Created April 9, 2013 02:45
Show Gist options
  • Save garrettmurray/5342519 to your computer and use it in GitHub Desktop.
Save garrettmurray/5342519 to your computer and use it in GitHub Desktop.
Use a UIRefreshControl with a UIViewController that contains a tableView property.
// Set up the UIRefreshControl.
self.refreshControl = [[UIRefreshControl alloc] init];
[self.refreshControl addTarget:self
action:@selector(refreshInvoked:forState:)
forControlEvents:UIControlEventValueChanged];
// Create a UITableViewController so we can use a UIRefreshControl.
UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:self.tableView.style];
tvc.tableView = self.tableView;
tvc.refreshControl = self.refreshControl;
[self addChildViewController:tvc];
@ZakariaJawas
Copy link

Thank you this worked like charm, this is a swift version of your code

refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(refreshTable), for: .valueChanged)
let tableViewController = UITableViewController(style: self.tableView.style)
tableViewController.tableView = self.tableView
tableViewController.refreshControl = refreshControl
self.addChild(tableViewController)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment