MJRefresh是MJ大神写的框架,很强大,好多外国开发者都在用!
具体代码如下:
-(void)loadMoreData:(NSString *)type { MainIndexList *model = [[MainIndexList alloc]init]; model.page = [NSString stringWithFormat:@"%d",self.page]; model.type = type; [hHttpRequest indexGetLists:model success:^(id response) { NSDictionary *dict = (NSDictionary *)response; NSString *codeStr = [NSString stringWithFormat:@"%@",dict[@"code"]]; if ([codeStr isEqualToString:@"0"]) { NSMutableArray *dataAry = [NSMutableArray arrayWithArray:dict[@"data"]]; NSMutableArray *ssAry = [NSMutableArray array]; NSLog(@"----%ld",dataAry.count); if (self.page == 1) { [self.datasAry removeAllObjects]; for (NSDictionary *dict in dataAry) { MainListModel *model = [MainListModel mj_objectWithKeyValues:dict]; [self.datasAry addObject:model]; } }else { for (NSDictionary *dict in dataAry) { MainListModel *model = [MainListModel mj_objectWithKeyValues:dict]; [ssAry addObject:model]; } [self.datasAry addObjectsFromArray:ssAry]; } if (dataAry.count == 0&&self.datasAry.count!=0) { NSLog(@"已经是最后一页了~"); } } [self.jrTableView reloadData]; [self.jrTableView.mj_header endRefreshing]; [self.jrTableView.mj_footer endRefreshing]; } failure:^(NSError *err) { [self.jrTableView.mj_header endRefreshing]; [self.jrTableView.mj_footer endRefreshing]; }]; }
数据转模型的方法:
1,建一个model,然后在.m方法里面实现:
-(void)setValue:(id)value forUndefinedKey:(NSString *)key { if ([key isEqualToString:@"id"]) { value = self.ida; } }
可以什么都不写
2,MJExtension类库,具体使用方法如下:
for (NSDictionary *dict in dataAry) { MainListModel *model = [MainListModel mj_objectWithKeyValues:dict]; [self.datasAry addObject:model]; }
这里仅做记录!