首先记得导入MJRefresh.h 如果用mj_header 报错,还要导入UIScrollView+MJRefresh.h
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
page = 1;
[self.data removeAllObjects];
[self requestInfo];
}];
self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
page++;
[self requestInfo];
}];
page = 1;
[self requestInfo];
其次,在请求结果处加以控制:
[NetHttpTool POST:dic success:^(id responseObject) {
[MBProgressHUD hideHUDForView:self.view];
for (NSDictionary *dic in responseObject[@"list"]) {
[self.data addObject:dic];
}
\\是否有下一页的控制条件
if ([responseObject[@"page"][@"total"] integerValue] <= self.data.count) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}else
{
[self.tableView.mj_footer resetNoMoreData];
}
[self.tableView reloadData];
[self endRefresh];
} failure:^(NSError *error) {
[self endRefresh];
[MBProgressHUD hideHUDForView:self.view];
}];