UIRefreshControl iOS 6 xcode

Does anyone have a short example of how to implement the new UIRefreshControl in xcode. I have a UITableViewController that displays Tweets, I want to be able to demolish and update.

+42
objective-c iphone xcode ios6 uirefreshcontrol
Sep 26 '12 at 17:14
source share
3 answers

You can simply set it in your viewDidLoad if you have a UITableViewController :

 UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; [refreshControl addTarget:self action:@selector(refresh) forControlEvents:UIControlEventValueChanged]; self.refreshControl = refreshControl; 

Then you can do your update material here:

 -(void)refresh { // do something here to refresh. } 

When you are done updating, call [self.refreshControl endRefreshing]; to stop update management as indicated by rjgonzo.

+68
Sep 26 '12 at 17:19
source share

You can also configure this in Interface Builder. Although it works at the moment, it only stores a couple lines of code.

Select the TableViewController scene and in the Attributes Inspector, you will find a drop-down list for the Update option. Set to Enabled. In the hierarchy of the view manager, you will notice that an “update control” has been added (you will not see anything visually added to the scene itself). What is strange is that after connecting Refresh Control to IBAction (value change event), the event does not seem to fire. I suppose the error is (?), But meanwhile, setting "Refreshing" to enable creates a UIRefreshControl object and sets it to the refreshControl property of the view controller. In this case, you can add an event processing line to the viewDidLoad method:

 [self.refreshControl addTarget:self action:@selector(refreshView:) forControlEvents:UIControlEventValueChanged]; 

In your refreshView: method, you can do some work and then stop the refresh animation:

 - (void)refreshView:(UIRefreshControl *)sender { // Do something... [sender endRefreshing]; } 
+32
Sep 27 '12 at 18:40
source share

Here you can take a picture and update

In UITableViewController.h add UIRefreshControl *refreshControl; and -(void) refreshMyTableView; global method declaration

and viewDidLoad UITableViewController.m

 //initialise the refresh controller refreshControl = [[UIRefreshControl alloc] init]; //set the title for pull request refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"pull to Refresh"]; //call he refresh function [refreshControl addTarget:self action:@selector(refreshMyTableView) forControlEvents:UIControlEventValueChanged]; self.refreshControl = refreshControl; 

and update the function with the date and time of the update

 -(void)refreshMyTableView{ //set the title while refreshing refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing the TableView"]; //set the date and time of refreshing NSDateFormatter *formattedDate = [[NSDateFormatter alloc]init]; [formattedDate setDateFormat:@"MMM d, h:mm a"]; NSString *lastupdated = [NSString stringWithFormat:@"Last Updated on %@",[formattedDate stringFromDate:[NSDate date]]]; refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:lastupdated]; //end the refreshing [refreshControl endRefreshing]; } 
+18
Oct 17
source share



All Articles