#import "MJRefresh/MJRefresh.h”
4、viewDidLoad 中添加
//上拉刷新 下拉加载
[self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self loadNewData];
});
}];
self.tableView.mj_header.automaticallyChangeAlpha = YES;
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// 设置了底部inset
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 30, 0);
// 忽略掉底部inset
self.tableView.mj_footer.ignoredScrollViewContentInsetBottom = 30;
5、自定义方法
#define kRandomData [NSString stringWithFormat:@"name %d",arc4random_uniform(1000)]
#pragma mark - 自定义方法
-(void) loadNewData {
for (int i = 0; i < 5; i++) {
[self.arr insertObject:kRandomData atIndex:0];
}
[self.tableView reloadData];
[self.tableView.mj_header endRefreshing];
}
-(void) loadMoreData {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
for (int i = 0; i < 5; i++) {
[self.arr addObject:kRandomData];
}
[self.tableView reloadData];
[self.tableView.mj_footer endRefreshing];
});
}