IOS control TableView Drop-down Refresh, load data __ios

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 package of pictures dragged into your project.

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

#import "EGORefreshTableHeaderView.h" @interface rootviewcontroller:uitableviewcontroller  {  
  
Egorefreshtableheaderview *_refreshheaderview; Reloading Var should really be your tableviews datasource  //Putting it-for demo purposes  BOOL _reloading;  
}-(void) Reloadtableviewdatasource; -(void) doneloadingtableviewdata; @end

Three, switch to your  uitableviewcontroller. m file, add the appropriate code: <pre class= "Prettyprint <a href=" http:= "data-ke-src=" www . ahlinux.com= "" php= "" "=" "target=" _blank "style=" word-wrap:break-word; font-size:16px; margin-top:0px; margin-bottom:0px; padding:0px; line-height:30px; Background-color:rgb (255, 255, 255); >php "> 1-(void) Viewdidload {2 [Super Viewdidload]; 3 4 if (_refreshheaderview = = nil) {5 6 Egorefreshtablehead Erview *view = [[Egorefreshtableheaderview alloc] Initwithframe:cgrectmake (0.0f, 0.0f- Self.tableView.bounds.size.height, Self.view.frame.size.width, Self.tableView.bounds.size.height)]; 7 view. delegate = self; 8 [Self.tableview Addsubview:view]; 9 _refreshheaderview = view; [View release]; One//update the last update date [_refreshheaderview refreshlastupdateddate];

}

 1 #pragma mark-2 #pragma mark Data Source loading/reloading Methods 3 4-(void) reloadtableviewdatasource{5 6  Should be calling your Tableviews the data source model to reload 7//Put here just for demo 8 _reloading = YES; 9 (void) doneloadingtableviewdata{//model should call this is done loading _reloading = NO; [_refreshheaderview EgoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView]; #pragma mark-21 #pragma mark Uiscrollviewdelegate Methods-(void) Scrollviewdidscroll: (Uiscrollvie W *) scrollview{[_refreshheaderview Egorefreshscrollviewdidscroll:scrollview] (MB)-(void) Scrollviewdiden Ddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate{[_refreshheaderview Egorefreshscrollviewdidenddragging:scrollview]; #pragma mark-36 #pragma mark Egorefreshtableheaderdelegate Methods-(void) Egorefreshtableheaderdi Dtriggerrefresh: (Egorefreshtableheaderview*) view{[self reloadtableviewdatasource]; [Self performselector: @selector (Doneloadingtableviewdata) Withobject:nil afterdelay:3.0]; (BOOL) Egorefreshtableheaderdatasourceisloading: (egorefreshtableheaderview*) view{return _reloading ; Should return if data source model is reloading-(nsdate*) egorefreshtableheaderdatasourcelastupdated: (E gorefreshtableheaderview*) view{[NSDate Date];//should return date data source is last changed 54 55}

Finally, don't forget the memory management habits, if it is arc management can not dealloc. If it is MRC, then write down all of the following memory releases:

1-(void) Viewdidunload {2 _refreshheaderview=nil 3} 4 5-(void) Dealloc {6 7 _refreshheaderview = nil; 8 [Super Deall OC]; 9}
PS: Transfer from others to share. This article from: Linux Tutorial Network
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.