popo继承pod ‘MJRefresh’
v.h
@property (nonatomic , assign)int page;
v.m
#import "ViewController.h"
#import <MJRefresh.h>
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{
UITableView *tab;
}
@property(nonatomic,strong)NSMutableArray * dataSource;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
tab=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
tab.delegate=self;
tab.dataSource=self;
[self.view addSubview:tab];
_dataSource = [NSMutableArray arrayWithObjects:@"张三",@"李四",@"王五",@"张三",@"李四",@"王五", nil];
self.page = 1;
[self addheaderRefresh];
[self addFooterRefresh];
}
//下拉
-(void)addheaderRefresh{
MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
//重新发送网络请求
[self loadData];
}];
tab.mj_header=header;
// 设置文字
[header setTitle:@"完事" forState:MJRefreshStateIdle];
[header setTitle:@"(ಥ _ ಥ)" forState:MJRefreshStatePulling];
[header setTitle:@"?" forState:MJRefreshStateRefreshing];
// 设置字体
header.stateLabel.font = [UIFont systemFontOfSize:15];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:14];
// 设置颜色
header.stateLabel.textColor = [UIColor redColor];
header.lastUpdatedTimeLabel.textColor = [UIColor blueColor];
// // 隐藏时间
// header.lastUpdatedTimeLabel.hidden = YES;
// // 隐藏状态
// header.stateLabel.hidden = YES;
}
//下拉添加
-(void)loadData{
//添加内容
[self.dataSource addObject:@"盖伦"];
//刷新表格
[self->tab reloadData];
//请求时间
sleep(2);
//下拉结束
[self->tab.mj_header endRefreshing];
}
//上拉加载
-(void)addFooterRefresh{
MJRefreshAutoGifFooter *footer=[MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
// 重新发送网络请求
[self removeData];
}];
tab.mj_footer = footer;
}
//上拉加载
-(void)removeData{
//删除最后一个
[_dataSource removeLastObject];
//刷新表格
[tab reloadData];
//加载时间
sleep(2);
//关闭加载
[tab.mj_footer endRefreshing];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[tab dequeueReusableCellWithIdentifier:@"cc"];
if(!cell){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"11"];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@",_dataSource[indexPath.row]];
// cell.textLabel.text=arr[indexPath.row];
return cell;
}
@end