导入完整的MJRefresh文件夹
头文件声明
#import"MJRefresh.h"
@property(nonatomic,retain)UITableView*tableView;
全局tableView,方便使用
//
// MYViewController.m
#import"MYViewController.h"
@interface MYViewController()
@end
@implementation MYViewController
//下拉刷新
-(void)headerRereshing
{
添加数据,想办法
// 2.2秒后刷新表格UI
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(2.0* NSEC_PER_SEC)), dispatch_get_main_queue(),^{
// 刷新表格
[self.tableView reloadData];
// (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
[self.tableView headerEndRefreshing];
});
}
//下拉加载
-(void)footerRereshing
{
// 2.2秒后刷新表格UI
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(2.0* NSEC_PER_SEC)), dispatch_get_main_queue(),^{
// 刷新表格
[self.tableView reloadData];
// (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
[self.tableView footerEndRefreshing];
});
}
- (void)viewDidLoad
{
[super viewDidLoad];
_array=[[NSArray alloc]initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil];
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 400) style:UITableViewStyleGrouped];
_tableView.delegate=self;
_tableView.dataSource=self;
[self.view addSubview:_tableView];
//集成刷新控件
[self setupRefresh];
// Do anyadditional setup after loading the view.
}
//刷新提示内容
- (void)setupRefresh
{
[_tableViewaddHeaderWithTarget:selfaction:@selector(headerRereshing)];
#warning自动刷新(一进入程序就下拉刷新)
[_tableViewheaderBeginRefreshing];
[_tableViewaddFooterWithTarget:selfaction:@selector(footerRereshing)];
// 设置文字(也可以不设置,默认的文字在MJRefreshConst中修改)
_tableView.headerPullToRefreshText = @"下拉可以刷新";
_tableView.headerReleaseToRefreshText = @"松开马上刷新";
_tableView.headerRefreshingText = @“数据加载中”;
_tableView.footerPullToRefreshText = @"上拉加载更多数据";
_tableView.footerReleaseToRefreshText = @"松开加载更多数据";
_tableView.footerRefreshingText = @“数据加载中”;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
return 11;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString*CellIndenttifier=@"Cell";
UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:CellIndenttifier];
if(cell==nil) {
cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndenttifier];
}
cell.textLabel.text=[_array objectAtIndex:[indexPath row]];
returncell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose ofany resources that can be recreated.
}
/*
#pragmamark - Navigation
//In a storyboard-based application, you will often want to do a littlepreparation before navigation
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [seguedestinationViewController].
// Pass the selected object to the new viewcontroller.
}
*/
@end