我有一个情况,我将从 Web 服务获得超过 25000 条记录,它使用分页技术发送。 所以问题是我只想存储数据,以便我考虑在循环中运行它,但将来的记录可能会有所不同(即 30000,50000 等(
从后端我每页上得到 10000 条记录,但我不知道我运行了多少次循环,那么我如何处理这个问题?
-(void)vendorsListCalling:(NSInteger)pageIndex{
[[ServicesHandler new] callVendorDetailsServiceWithParams:@{@"pageno":@(pageIndex)} CompletionBLock:^(NSDictionary *response, NSError *error) {
if (error) {
NSLog(@"error log %@",error.localizedDescription);
}else{
NSDictionary *dict = response[@"params"][@"data"];
[vendorDictionay addEntriesFromDictionary:dict];
pageCount++;
[[NSUserDefaults standardUserDefaults] setObject:vendorDictionay forKey:@"vendorsDict"];
}
}];
}
上面的块是我卡住的地方.
任何建议将不胜感激。
您可以将数据存储到 sqlite 数据库中。对于递归调用服务,您可以修改与以下相同的方法:
-(void)vendorsListCalling:(NSInteger)pageIndex {
if (!loader) {
//Write code to Show your loader here
}
[[ServicesHandler new] callVendorDetailsServiceWithParams:@{@"pageno":@(pageIndex)} CompletionBLock:^(NSDictionary *response, NSError *error) {
if (error) {
NSLog(@"error log %@",error.localizedDescription);
//If it fails you need to call the service again with the same Index
[self vendorsListCalling:pageCount];
} else {
if (!response[@"params"][@"data"]) {
//Stop loader since you didn't received any data
} else {
NSDictionary *dict = response[@"params"][@"data"];
[vendorDictionay addEntriesFromDictionary:dict];
pageCount++;
// Store Data in database here //
//Call service with incremented Index
[self vendorsListCalling:pageCount];
}
}
}];
}