ios开发之--MJRefresh的简单使用

时间:2021-03-13 22:44:52

MJRefresh是MJ大神写的框架,很强大,好多外国开发者都在用!

具体方法如下:

-(void)requestData
{
NSString *userIdStr = [NSString stringWithFormat:@"%@",[DEFAULTS objectForKey:USERID]]; self.pageNums ++; HStart(self.view);
[hHttpEngine getRongNoticeAction:userIdStr page:[NSString stringWithFormat:@"%ld",(long)self.pageNums] success:^(id response) { HStop(self.view);
NSDictionary *dict = (NSDictionary *)response; NSString *codeStr = [NSString stringWithFormat:@"%@",dict[@"code"]]; if ([codeStr isEqualToString:@""]) { if (self.pageNums == ) {
[self.contentAry removeAllObjects];
} self.dataAry = [NSMutableArray arrayWithArray:dict[@"data"]]; if (self.dataAry.count > ) { self.dataStatusView.hidden = YES;
newNotiTableV.hidden = NO; for (NSDictionary *dict in self.dataAry) {
NewNotiModel *model = [NewNotiModel mj_objectWithKeyValues:dict];
[self.contentAry addObject:model];
}
}else
{
if (self.contentAry.count == ) {
self.dataStatusView.hidden = NO;
self.dataStatusView.dataStatus = DataStatus_noData;
newNotiTableV.hidden = YES;
}else
{
self.dataStatusView.hidden = YES;
newNotiTableV.hidden = NO;
}
self.pageNums --;
} }else
{
HStop(self.view);
show_msg(@"网络错误");
} [newNotiTableV reloadData];
[newNotiTableV.mj_footer endRefreshing];
[newNotiTableV.mj_header endRefreshing]; } failure:^(NSError *err) {
HStop(self.view);
[newNotiTableV.mj_footer endRefreshing];
[newNotiTableV.mj_header endRefreshing];
}];
}

方法调用,在tableview初始化的时候调用:

newNotiTableV.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
[self requestData];
}]; newNotiTableV.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
self.pageNums = ;
[self requestData];
}];

数据转模型的方法:

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];
}

这里仅做记录!