IOS控制項 Tableview 下拉重新整理,載入資料__IOS

來源:互聯網
上載者:User

一、 點擊此連連結下載資源檔,將 EGORefreshTableHeaderView.h 、 EGORefreshTableHeaderView.m 兩個檔案,以及Enormego提供的那一套圖片包拖進你的工程裡。

二、找到你的  UITableViewController 的 .h 檔案,添加相應的代碼:

#import "EGORefreshTableHeaderView.h" @interface RootViewController : UITableViewController  {    EGORefreshTableHeaderView *_refreshHeaderView; // Reloading var should really be your tableviews datasource  // Putting it here for demo purposes  BOOL _reloading;  } - (void)reloadTableViewDataSource; - (void)doneLoadingTableViewData; @end

三、切換到你的  UITableViewController 的 .m 檔案,添加相應的代碼: <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 EGORefreshTableHeaderView *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; 10 [view release]; 11 12 } 13 14 // update the last update date 15 [_refreshHeaderView refreshLastUpdatedDate]; 16 }

 1 #pragma mark -   2 #pragma mark Data Source Loading / Reloading Methods   3  4 - (void)reloadTableViewDataSource{  5  6 // should be calling your tableviews data source model to reload   7 // put here just for demo   8 _reloading = YES;  9 10 } 11 12 - (void)doneLoadingTableViewData{ 13 14 // model should call this when its done loading  15 _reloading = NO; 16 [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView]; 17 18 } 19 20 #pragma mark -  21 #pragma mark UIScrollViewDelegate Methods  22 23 - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 24 25 [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView]; 26 27 } 28 29 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{ 30 31 [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView]; 32 33 } 34 35 #pragma mark -  36 #pragma mark EGORefreshTableHeaderDelegate Methods  37 38 - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{ 39 40 [self reloadTableViewDataSource]; 41 [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0]; 42 43 } 44 45 - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{ 46 47 return _reloading; // should return if data source model is reloading  48 49 } 50 51 - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{ 52 53 return [NSDate date]; // should return date data source was last changed  54 55 }

四、最後呢,別忘了記憶體管理習慣,如果是ARC管理則可以不用dealloc。如果是MRC的話,就把下面的那個全部記憶體釋放寫上:

1 - (void)viewDidUnload { 2 _refreshHeaderView=nil; 3 } 4 5 - (void)dealloc { 6 7 _refreshHeaderView = nil; 8 [super dealloc]; 9 }
PS:轉自他人分享。 本文來自:Linux教程網
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.