Quick and Complete UIRefreshControl Tutorial
Check out this link:
http://www.intertech.com/Blog/ios-6-pull-to-refresh-uirefreshcontrol/
This is the how you implement GCD to show the spinner:
- (void)viewDidLoad
{
[super viewDidLoad];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to refresh"];
[refreshControl addTarget:self action:@selector(refreshing:) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshControl;
}
This is the refreshing method
- (void)refreshing:(UIRefreshControl *)refresh
{
NSLog(@"Refreshing...");
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Refreshing data..."];
[refresh beginRefreshing];
dispatch_queue_t queue = dispatch_queue_create("table view loading queue", NULL);
dispatch_async(queue, ^{
sleep(5);
dispatch_async(dispatch_get_main_queue(), ^{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM d, h:mm a"];
NSString *lastUpdated = [NSString stringWithFormat:@"Last updated on %@", [formatter stringFromDate:[NSDate date]]];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated];
[refresh endRefreshing];
});
});
}













