如何在iOS中使用PFQuery提取表中的所有数据? [英] How to Fetch all data in a table using PFQuery in iOS?

查看:80
本文介绍了如何在iOS中使用PFQuery提取表中的所有数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS和Parse Framework的新手,我想像

i am newbie here in iOS and Parse Framework i want to fetch data from my Parse table from PFQuery like as

NSUInteger limit = 1500;
PFQuery *query = [PFQuery queryWithClassName:@"MapInfo"];
[query setLimit: limit];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
{
    if (!error) {
        NSLog(@"Successfully retrieved: %@", objects);
    } else {
        NSString *errorString = [[error userInfo] objectForKey:@"error"];
        NSLog(@"Error: %@", errorString);
    }
}];

它正在按我的要求工作,但是它只给我1000个对象,我想在这里获取包含2000个对象的所有表数据,并且它将逐日增加,请为此提供帮助.

it is Working as i want but it is give me only 1000 objects i want here to fetch all my table data it contain unto 2000 object and it will increment as day by day please help me for this.

为此,我现在编写这样的代码,但它只是只给我1000个对象"

For this Now i write a code like this but it is Only Give me 1000 Objects only

 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) {
        [allObjects addObjectsFromArray:objects];
        if (objects.count == limit) {

            skip += limit;
            [query setSkip: skip];
            [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
                NSLog(@"Array %@",objects);
            }];
             }

             } else {
                 NSLog(@"Error: %@ %@", error, [error userInfo]);
             }
             }];

谢谢.

推荐答案

https://parse.com/questions/fetch-all-data-in-a-table-using-pfquery

您可以使用skip and limit参数对表中的所有对象进行分页,方法是添加limit的值以跳过直到查询返回的对象数量小于limit为止.

You can use the skip and limit parameter to paginate through all objects in the table by adding the value of limit to skip until the query returns an amount of objects that is less than limit.

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];
      [query findObjects... // Execute the query until all objects have been returned. Keep adding the results to the allObjects mutable array.

    }
  } else {
    // Log details of the failure
    NSLog(@"Error: %@ %@", error, [error userInfo]);
  }
}];

这篇关于如何在iOS中使用PFQuery提取表中的所有数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆