A new control in iOS6.0, UIRefreshControl
Example
I saw a post posted by someone else on the forum today, saying that this control can only be used in UITableViewController. If it is used in other viewcontrollers, the following error message will be displayed during runtime: (that is, UIRefreshControl can only be managed by UITableViewController)
In fact, he ignored a point and can call it on ViewController.
- (void)addSubview:(UIView *)view;
To add UITableViewController, and then add UITableView, so that UIRefreshControl is still managed by UITableViewController, but it can still be used in other viewcontrollers. To use the native drop-down effect, do you think it is easy for us!
Example structure:
VC_view inherits from UIViewController
TV _table inherits from UITableViewController
Key code of VC_view
# Pragma mark-# pragma mark Custom Methods /****************************** **************************************** * ******* Function Name: -(void) refreshData Function Description: refresh View data input parameter: N/A output parameter: N/A return parameter: N/A remarks: **************************************** **************************************/- (void) refreshData {self. pTV_table = [[TV _table alloc] initWithNibName: @ "TV _table" bundle: nil]; self. pTV_table.view.frame = CGRectMake (0, 0,320,416); [_ pV_main addSubview: _ pTV_table.tableView];}
Global variables must be declared when you add another Controller Or View to UIViewController.
// When UITableViewController is introduced, its global variables must be declared in the Controller to be introduced and cannot be declared as local variables. @ Property (strong, nonatomic) TV _table * pTV_table;
This is a feature of ARC.
Key code of TV _table
/*************************************** * ************************************ Function name: -(void) configRefreshControl Function Description: Configure RefreshControl input parameter: N/A output parameter: N/A return parameter: N/A remarks: **************************************** **************************************/- (void) configRefreshControl {UIRefreshControl * refresh = [[UIRefreshControl alloc] init]; refresh. tintColor = [UIColor lightGrayColor]; refresh. attributedTitle = [[NSAttributedString alloc] initWithString: @ "pull-down refresh"]; [refresh addTarget: self action: @ selector (refreshView) forControlEvents: UIControlEventValueChanged]; self. refreshControl = refresh ;}
/*************************************** * ************************************ Function name: -(void) handleData Function Description: processing data input parameter: N/A output parameter: N/A return parameter: N/A remarks: **************************************** **************************************/- (void) handleData {NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat: @ "yyyy MM dd HH: mm: ss"]; NSString * lastUpdated = [NSString stringWithFormat: @ "Last updated on % @", [formatter stringFromDate: [NSDate date]; self. refreshControl. attributedTitle = [[NSAttributedString alloc] initWithString: lastUpdated]; self. count ++; [_ pMuArr_dataSource insertObject: [NSString stringWithFormat: @ "% d. % @, too many simple WZP feelings ", _ count, [formatter stringFromDate: [NSDate date] atIndex: 0]; [self. refreshControl endRefreshing]; [self. tableView reloadData];}
/*************************************** * ************************************ Function name: -(void) refreshView Function Description: refresh view input parameter: N/A output parameter: N/A return parameter: N/A remarks: **************************************** **************************************/- (void) refreshView {if (self. refreshControl. refreshing) {self. refreshControl. attributedTitle = [[NSAttributedString alloc] initWithString: @ "load data... "]; [self defined mselector: @ selector (handleData) withObject: nil afterDelay: 2] ;}}
PRJ_pullDownRefresh6.0.zip: http://ishare.iask.sina.com.cn/f/34851880.html