2、找到你的 UITableViewController 的 .h 文件,添加相應的代碼:java
#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
3、切換到你的 UITableViewController 的 .m 文件,添加相應的代碼:linux
<pre class="prettyprint <a href=" http:=" data-ke-src=" www.ahlinux.com="" php="" "="" target="_blank" style="word-wrap: break-word; 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 }git
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 }
4、最後呢,別忘了內存管理習慣,若是是ARC管理則能夠不用dealloc。若是是MRC的話,就把下面的那個所有內存釋放寫上:github
1 - (void)viewDidUnload { 2 _refreshHeaderView=nil; 3 } 4 5 - (void)dealloc { 6 7 _refreshHeaderView = nil; 8 [super dealloc]; 9 }
PS:轉自他人分享。ruby
本文來自:Linux教程網ide