项目中经常用到翻页请求数据,这个类就能快速的实现。
使用方法:
1、在VC中添加属性变量
@property (strong, nonatomic) JMRefreshTool *refreshTool;
2、结合接口一起使用
-(void)requestBillList{
if(self.refreshTool == nil){
JMWeak(self);
self.refreshTool = [[JMRefreshTool alloc] initWithScrollView:self.tableView dataAnalysisBlock:^NSArray *(NSDictionary *responseData) {
NSMutableArray *array = [[NSMutableArray alloc] init];
NSDictionary *dataDic = responseData[@"data"];
NSString *income = [dataDic getJsonValue:@"income"];
NSString *expend = [dataDic getJsonValue:@"expend"];
weakself.totalLabel.text = [NSString stringWithFormat:@"支出%@ 收入%@",expend,income];
NSArray *listArray = dataDic[@"page"][@"list"];
for(NSDictionary *dic in listArray){
WalletBillModel *model = [[WalletBillModel alloc] initWithDictionary:dic];
[array addObject:model];
}
if([weakself.refreshTool isAddData]){
[weakself.tableData addObjectsFromArray:array];
}else{
weakself.tableData = array;
}
[weakself.tableView reloadData];
return array;
}];
self.refreshTool.requestUrl = kUrlWalletBillList;
}
NSMutableDictionary *params = [JMCommonMethod baseRequestParams];
[params setJsonValue:self.selectType.requestType key:@"msgType"];
[params setJsonValue:[self.month stringWithFormat:@"yyyy-MM"] key:@"month"];
self.refreshTool.requestParams = params;
[self.tableView.mj_header beginRefreshing];
}
responseData就是接口返回的数据,解析成自己的model使用即可。 注意使用weakself。