iOS 6 : UIRefreshControl For TableView Updates

With iOS 6, Apple introduced a new UI control for initiating a refresh on a UITableViewController.

The video below shows the control in a simple tableview. For each refresh request I add a new row to the table:


To add the refresh control to a tableview, use code similar to the following:

// Create the refresh control
UIRefreshControl *refreshControl = [[[UIRefreshControl alloc] init] autorelease];
 
// Set the action
[refreshControl addTarget:self action:@selector(refreshControlRequest)
    forControlEvents:UIControlEventValueChanged];
 
// Optional tint
[refreshControl setTintColor:[UIColor colorWithRed:0.000 green:0.000 blue:0.630 alpha:1.000]];
 
// Assign control to the tableview    
[self setRefreshControl: refreshControl];

The event UIControlEventValueChanged is generated when a refresh is requested. To receive the event, you assign an action method as shown above. Inside the action method you update the table as needed:

- (void)refreshControlRequest
{
  NSLog(@"refreshing...");
 
 // Update the table
 ...
 
}