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