iOS开源项目:PullToRefresh

PullToRefresh实现了类似微博下拉刷新的功能:https://github.com/sonnyparlin/PullToRefresh

 首先把PullToRefreshView.h, PullToRefreshView.m, arrow.png and [email protected] QuartzCore framework and 和 AudioToolbox framework加入到工程中。

然后继承UITableView创建自定义View,并引入PullToRefreshView.h

#import "PullToRefreshView.h"
@interface MyTableVIew : UITableView{
    
}

然后需要一个PullToRefreshView变量

@implementation RootViewController
{
PullToRefreshView *pull;
}

并初始化这个view:

pull = [[PullToRefreshView alloc] initWithScrollView:(UIScrollView *) self.tableView];
[pull setDelegate:self];
[self.tableView addSubview:pull];

实现PullToRefreshViewDelegate代理方法:

- (void)pullToRefreshViewShouldRefresh:(PullToRefreshView *)view;
{

  [self performSelectorInBackground:@selector(reloadTableData) withObject:nil];

}

最后刷新页面:

-(void) reloadTableData
{
// call to reload your data
...
[self.tableView reloadData];
[pull finishedLoading];
}

参考:

http://sonnyparlin.com/2011/12/pulltorefresh-ios-5-and-arc-tutorial/

源码:
https://www.dropbox.com/s/bkum1jc1z9xqc9x/PullToRefreshDemo.zip

你可能感兴趣的:(refresh)