热门搜索 :
考研考公
您的当前位置:首页正文

上拉加载更早时候的数据请求接口开发思路

来源:东饰资讯网

1. JSON数据,使用AFNetworking第三方框架。

2. 取出最后面的微博(最新的微博,ID最大的微博),若指定此参数,这返回ID小于或等于max_id的微博,默认为0。

3. ID这种数据一般都是比较大的,一般转成整数的话,最好是long long类型。

4. 将“微博字典”的数组 转为 “微博模型”数组。

5. 将更多的微博数据,添加到总数组的最后面,刷新表格,结束刷新(隐藏footer)。

开发代码:

/**

*  加载更多的微博数据

*/

- (void)loadMoreStatus

{

// 1.请求管理者

AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];

// 2.拼接请求参数

HWAccount *account = [HWAccountTool account];

NSMutableDictionary *params = [NSMutableDictionary dictionary];

params[@"access_token"] = account.access_token;

// 取出最后面的微博(最新的微博,ID最大的微博)

HWStatus *lastStatus = [self.statuses lastObject];

if (lastStatus) {

// 若指定此参数,则返回ID小于或等于max_id的微博,默认为0。

// id这种数据一般都是比较大的,一般转成整数的话,最好是long long类型

long long maxId = lastStatus.idstr.longLongValue - 1;

params[@"max_id"] = @(maxId);

}

// 3.发送请求

// 将 "微博字典"数组 转为 "微博模型"数组

NSArray *newStatuses = [HWStatus objectArrayWithKeyValuesArray:responseObject[@"statuses"]];

// 将更多的微博数据,添加到总数组的最后面

[self.statuses addObjectsFromArray:newStatuses];

// 刷新表格

[self.tableView reloadData];

// 结束刷新(隐藏footer)

self.tableView.tableFooterView.hidden = YES;

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

HWLog(@"请求失败-%@", error);

// 结束刷新

self.tableView.tableFooterView.hidden = YES;

}];

}

Top