个人是使用了一个JHfresh的第三方库,需要使用的同学可以自行去下载,我就不贴出来了。
- (void)refresh
{
__weak typeof (self)ws = self;
// 上拉刷新.
[_tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
ws.page = 1;
[ws downloadData];
}];
// 下拉加载更多.
[_tableView addRefreshFooterViewWithAniViewClass:[JHRefreshCommonAniView class] beginRefresh:^{
ws.page ++;
[ws downloadData];
}];
}
-(void)downloadData
{
NSString *urlString = [NSString stringWithFormat:self.urlString,_page,_categoryId];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
if(_page == 1)
{
NSLog(@"refresh");
[_dataArray removeAllObjects];
}
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
NSArray *apps = dict[@"applications"];
for (NSDictionary *appDict in apps) {
//NSLog(@"name = %@",appDict[@"name"]);
//[ZJModelTool createModelWithDictionary:appDict modelName:@"AppModel"];
AppModel *model = [[AppModel alloc] init];
[model setValuesForKeysWithDictionary:appDict];
NSLog(@"%@",model.name);
model.desc = appDict[@"description"];
[_dataArray addObject:model];
}
[_tableView reloadData];
[_tableView headerEndRefreshingWithResult:JHRefreshResultSuccess];
[_tableView footerEndRefreshing];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}
网友评论