1.用UITableViewController
#import <UIKit/UIKit.h>
@interface RefreshViewController :UITableViewController
@end
- (void)viewDidLoad
{
[superviewDidLoad];
UIRefreshControl *refreshC = [[UIRefreshControlalloc] init];
refreshC.tintColor = [UIColorblackColor];
refreshC.attributedTitle = [[NSAttributedStringalloc] initWithString:@"下拉刷新"];
[refreshC addTarget:selfaction:@selector(refreshView:)forControlEvents:UIControlEventValueChanged];
self.refreshControl = refreshC;
}
- (void)refreshView:(UIRefreshControl*)refreshControl
{
if (refreshControl.refreshing)
{
refreshControl.attributedTitle = [[NSAttributedStringalloc] initWithString:@"refreshing..."];
[selfperformSelector:@selector(loadData)];
}
}
- (void)loadData
{
//load data
[self.refreshControl endRefreshing];
[self.tableViewreloadData];
}
2.UIRefreshView + UITableView
@interface DefaultTableView :UITableView
@end
- (id)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self) {
// Initialization code
UIRefreshControl *refreshView = [[UIRefreshControlalloc] init];
refreshView.attributedTitle = [[NSAttributedStringalloc] initWithString:@"下拉刷新"];
[refreshView addTarget:selfaction:@selector(refreshView:)forControlEvents:UIControlEventValueChanged];
[selfaddSubview:refreshView];
}
return self;
}
- (void)refreshView:(UIRefreshControl*)refreshView
{
if (refreshView.refreshing)
{
refreshView.attributedTitle = [[NSAttributedStringalloc] initWithString:@"loading..."];
[selfperformSelector:@selector(loadDataForTableView:)withObject:refreshView];
}
}
- (void)loadDataForTableView:(UIRefreshControl*)refreshView
{
//load data
}