#import "ViewController.h"
#import "MJRefresh.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray*_dataSource;
UITableView *tbv;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
tbv.delegate=self;
tbv.dataSource = self;
[self.view addSubview:tbv];
_dataSource = [NSMutableArray arrayWithObjects:@"张三",@"李四",@"王五",@"张三",@"李四",@"王五", nil];
self.page=1;
[self addHeaderRefresh];
[self addFooterRefresh];
}
-(void)addHeaderRefresh{
MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
// (3)重新发送网络请求
[selfloadData];
}];
tbv.mj_header= header;
}
-(void)loadData{
[_dataSource addObject:@"盖伦"];
[tbv reloadData];
sleep(2);
[tbv.mj_header endRefreshing];
}
// 上拉加载
-(void)addFooterRefresh{
MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
// 页面增加
// 重新发送网络请求
[selfremoveData];
}];
tbv.mj_footer= footer;
}
-(void)removeData{
[_dataSource removeLastObject];
[tbv reloadData];
sleep(2);
[tbv.mj_footer endRefreshing];
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return _dataSource.count;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
}
cell.textLabel.text = [NSString stringWithFormat:@"%@",_dataSource[indexPath.row]];
returncell;
}
@end
网友评论