-(void)refresh{
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[self updateDataWithComponent:self.tableView.mj_header ];
}];
self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
[self updateDataWithComponent:self.tableView.mj_footer ];
}];
[self.tableView.mj_header beginRefreshing];
}
- (void)updateDataWithComponent:(id)component
{
if([componentisKindOfClass:[MJRefreshHeaderclass]])
{
self.page=1;
}
elseif([componentisKindOfClass:[MJRefreshFooterclass]])
{
self.page++;
}
[[LNOthernetWork defaults] GetPeopleMessageWithunitId:@"986" index:[NSString stringWithFormat:@"%lu",self.page] size:[NSString stringWithFormat:@"%d",PAGE_SIZE_] WithProgressBlock:^(NSProgress * _Nonnull downloadProgress) {
}WithSucBlock:^(id _Nonnullresponseobj) {
if([responseobj[@"status"]intValue] ==1) {
[selfendRefresh];
if([componentisKindOfClass:[MJRefreshHeaderclass]]) {
[self.MessageArrayremoveAllObjects];
}
NSArray* rowArray = responseobj[@"list"];
for(NSDictionary* dictinrowArray) {
LNPeopleModel * model = [LNPeopleModel GetMessageWithDict:dict];
[self.MessageArray addObject:model];
}
[self.tableViewreloadData];
[selfendRefreshWithComponent:componentrealSize:rowArray.countsize:PAGE_SIZE_];
}else{
[selfendRefresh];
}
}WithFailBlock:^(NSError*_Nonnullerror) {
}];
}
- (void)endRefresh{
[self.tableView.mj_header endRefreshing];
[self.tableView.mj_footer endRefreshing];
}
/**
结束刷新的方法
@param component 刷新的控件mj_header或者mj_footer
@param realSize 网络请求实际拿到的数量
@param size 网络请求要拿取得数量 (实际数量小于要拿取的数量,说明已经没有更多的数据)
*/
- (void)endRefreshWithComponent:(id)component realSize:(NSInteger)realSize size:(NSInteger)size
{
if(component && [componentisKindOfClass:[MJRefreshHeaderclass]]) {
[componentendRefreshing];
[self.tableView.mj_footer resetNoMoreData];
}
elseif(component && [componentisKindOfClass:[MJRefreshFooterclass]])
{
if(realSize < size) {
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}
else{
[self.tableView.mj_footer resetNoMoreData];
}
}
}
网友评论