一、 點擊此連連結下載資源檔,將 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教程網