Using UIRefreshControl
2012-11-02 Updated 2025-12-31 · dc272e6Prerequisites: You should be able to create a project and set up a UITableViewController and table view in the storyboard. Description: Lets start by setting up a new project with a UITableViewController I wont bother populating it as this isn't required to get the UIRefreshControl working.Basically all we have to do after setting up the table is to create a UIRefreshControl ,set it up and customise if you wish ,give it a target method with which to handle the refreshing and then add the refreshControl to self. The most logical place for this of corse being in the viewDidLoad. Code:
- (void)viewDidLoad
{
[super viewDidLoad];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.tintColor = [UIColor redColor]; // you can customize the tint color
// tell refreshControl where its refreshing will be handled
[refreshControl addTarget:self action:@selector(refreshing:)
forControlEvents:UIControlEventValueChanged];
[self setRefreshControl:refreshControl];
}
- (void)refreshing:(UIRefreshControl *)refreshControl
{
// refresh code here (reload table data etc.)
[refreshControl endRefreshing];
}
The result :
It really is that simple, for more , read Apples documentation.
Originally posted on Blogspot