4.10. Displaying a Refresh Control for Table Views
Problem
You want to display a nice refresh UI control on top of your table views that allows your users to intuitively pull down the table view in order to update its contents. An example of a refresh control is shown in Figure 4-24.

Figure 4-24. A refresh control is displayed on top of a table view
Solution
Simply create a table view controller (as discussed in Recipe 4.9)
and set its refreshControl property
to a new instance of UIRefreshControl
class, as shown here:
-(id)initWithStyle:(UITableViewStyle)style{self=[superinitWithStyle:style];if(self){[self.tableViewregisterClass:[UITableViewCellclass]forCellReuseIdentifier:CellIdentifier];self.allTimes=[NSMutableArrayarrayWithObject:[NSDatedate]];/* Create the refresh control */self.refreshControl=[[UIRefreshControlalloc]init];self.refreshControl=self.refreshControl;[self.refreshControladdTarget:selfaction:@selector(handleRefresh:)forControlEvents:UIControlEventValueChanged];}returnself;}
Discussion
Refresh controls are simple visual indicators that appear on top of table views and tell the user that something is about to get updated. For instance, prior to iOS 6, in order to refresh your mailbox in the Mail app, you had to press a refresh button. In the new iOS, now you can simply drag the list of your emails down, as if you wanted to see what’s above there ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access