Apply pull-down refresh only to IOS 6.0

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.