pragma mark - 请求数据
-(void)createRefresh
{//调用明杰刷新
_tableView.header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)]; _tableView.footer = [MJRefreshAutoFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
// 第一次进入的时候先刷新一次
[_tableView.header beginRefreshing];
}
//下拉刷新
-(void)loadNewData
{
_page = 0;
self.dataArray = [NSMutableArray arrayWithCapacity:0];
[self getData];
}
//上拉加载
-(void)loadMoreData
{
_page ++;
[self getData];
}
-(void)getData
{
//手动设置格式,默认支持json
AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", nil];
[manager GET:[NSString stringWithFormat:ARTICALURL,_page] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSArray * array = responseObject[@"data"]; for (NSDictionary * dic in array) { ReadModel * model = [[ReadModel alloc]init]; [model setValuesForKeysWithDictionary:dic]; [self.dataArray addObject:model]; } if (_page == 0) { [_tableView.header endRefreshing]; } else { [_tableView.footer endRefreshing]; } [_tableView reloadData]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"%@",error); }];
}