PFQuery 只返回 100 个对象 (iOS)
Posted
技术标签:
【中文标题】PFQuery 只返回 100 个对象 (iOS)【英文标题】:PFQuery returns just 100 objects (iOS) 【发布时间】:2016-01-04 08:08:17 【问题描述】:我创建了一个 PFQuery 来获取“相册”类中的所有对象(512 个对象)。
当我创建一个 PFQuery 并对其调用 findObjectsInBackgroundWithBlock
方法时,它只返回 100 个对象而不是 512 个,尽管我添加了该行
query.limit=1000;
我的代码:
PFQuery *query=[PFQuery queryWithClassName:@"Albums"];
query.limit=1000;
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error)
if (error)
NSLog(@"Error: %@",[error description]);
NSLog(@"%lu",objects.count); //print - 100
self.albums=objects;
NSLog(@"%ld",(long)self.supermarkets.count); //print - 100
];
【问题讨论】:
PFQuery Only Returning 100的可能重复 【参考方案1】:试试这个 https://parse.com/questions/fetch-all-data-in-a-table-using-pfquery ..
NSMutableArray *allObjects = [NSMutableArray array];
NSUInteger limit = 0;
__block NSUInteger skip = 0;
PFQuery *query = [PFQuery queryWithClassName:@"MapInfo"];
[query setLimit: limit];
[query setSkip: skip];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
if (!error)
// The find succeeded. Add the returned objects to allObjects
[allObjects addObjectsFromArray:objects];
if (objects.count == limit)
// There might be more objects in the table. Update the skip value and execute the query again.
skip += limit;
[query setSkip: skip]; //from here you run the query again with new offset
else
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
];
【讨论】:
以上是关于PFQuery 只返回 100 个对象 (iOS)的主要内容,如果未能解决你的问题,请参考以下文章