iOS control Tableview drop-down refresh, load data

Source: Internet
Author: User

First, click on this link to download the resource file, will, EGORefreshTableHeaderView.h EGORefreshTableHeaderView.m two files, and Enormego provided by the set of picture package dragged into your project.

Second, find your uitableviewcontroller. h file and add the appropriate code:

  #import  "    @    Interface   Rootviewcontroller:uitableviewcontroller {    Egorefreshtableheaderview  *_refreshheaderview;  //  reloading var should really be your Tableviews datasource   putting it here  For demo purposes  bool _reloading;  } -(void  -(void    @end  


Third, switch to your uitableviewcontroller. m file and add the appropriate code:

  

1- (void) Viewdidload {2 [Super Viewdidload]; 3   4 if(_refreshheaderview = =Nil) {  5   6Egorefreshtableheaderview *view = [[Egorefreshtableheaderview alloc] Initwithframe:cgrectmake (0.0f,0.0f-self.tableView.bounds.size.height, Self.view.frame.size.width, Self.tableView.bounds.size.height)]; 7View.Delegate=Self ; 8 [Self.tableview Addsubview:view]; 9_refreshheaderview =view; Ten [view release];  One    A }   -    - //update the last update date the [_refreshheaderview refreshlastupdateddate];  -}

1 #pragmaMark-2 #pragmaMark Data Source loading/reloading Methods3   4- (void) reloadtableviewdatasource{5   6 //should is calling your Tableviews data source model to reload7 //put here just for demo8_reloading =YES; 9   Ten }   One    A- (void) doneloadingtableviewdata{ -    - //model should call the when it is done loading the_reloading =NO;  - [_refreshheaderview EgoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];  -    - }   +    - #pragmaMark- + #pragmaMark Uiscrollviewdelegate Methods A    at- (void) Scrollviewdidscroll: (Uiscrollview *) scrollview{ -    - [_refreshheaderview Egorefreshscrollviewdidscroll:scrollview];  -    - }   -    in- (void) Scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate{ -    to [_refreshheaderview Egorefreshscrollviewdidenddragging:scrollview];  +    - }   the    * #pragmaMark- $ #pragmaMark Egorefreshtableheaderdelegate MethodsPanax Notoginseng    -- (void) Egorefreshtableheaderdidtriggerrefresh: (egorefreshtableheaderview*) view{ the    + [self reloadtableviewdatasource];  A[Self performselector: @selector (doneloadingtableviewdata) Withobject:nil Afterdelay:3.0];  the    + }   -    $-(BOOL) egorefreshtableheaderdatasourceisloading: (egorefreshtableheaderview*) view{ $    - return_reloading;//should return if data source model is reloading -    the }   -   Wuyi-(nsdate*) egorefreshtableheaderdatasourcelastupdated: (egorefreshtableheaderview*) view{ the    - return[NSDate Date];//should return date data source is last changed Wu    -}

Four, finally, do not forget the memory management habits, if it is arc management can not dealloc. In the case of MRC, write all of the following memory releases:

1 -(void) viewdidunload {  2 _refreshheaderview=nil;   3 }  4   5 -(void) dealloc {  6   7 _refreshheaderview = nil;   8 [Super Dealloc];   9 }  

PS: Transfer from others to share.

iOS control Tableview drop-down refresh, load data

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.