美文网首页
iOS- JHfresh 上拉刷新,上拉加载更多

iOS- JHfresh 上拉刷新,上拉加载更多

作者: 亦晴工作室 | 来源:发表于2016-08-25 11:08 被阅读73次

个人是使用了一个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) {
        
    }];
}

相关文章

网友评论

      本文标题:iOS- JHfresh 上拉刷新,上拉加载更多

      本文链接:https://www.haomeiwen.com/subject/agkosttx.html