PFQuery FindObjectsInBackground返回0

use*_*452 9 xcode ios parse-platform pfquery pfobject

在我的UIViewController我试图查询我的解析服务器,但我不断得到它的返回0,虽然我知道100%这个类确实有对象.有什么想法吗?

 PFQuery *query = [PFQuery queryWithClassName:@"General"];

 int i;
 for (i = 0; i < [follows count]; i++) {
        [query whereKey:@"Session" containedIn:follows];
 }
 query.cachePolicy = kPFCachePolicyCacheThenNetwork;

 [query orderByDescending:@"createdAt"];
 [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
 // it never gets here...
 NSLog(@"OBJECTS%@", objects);
 if (!error) {
     NSLog(@"Successfully retrieved %lu objects.", (unsigned long)objects.count);
     for (PFObject *object in objects) {
         NSLog(@"%@", object.objectId);
     }

     // [self gotoMain];
 } else {
       NSLog(@"Error: %@ %@", error, [error userInfo]);
   }
 }];
Run Code Online (Sandbox Code Playgroud)

它告诉我在控制台中成功检索0个对象没有错误.

Rei*_*ner 1

正如其他人已经建议的那样,我首先会做最简单的查询:

PFQuery *query = [PFQuery queryWithClassName:@"General"];
 [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
 if (!error) {
     NSLog(@"Successfully retrieved %lu objects.", (unsigned long)objects.count);
 } else {
       NSLog(@"Error: %@ %@", error, [error userInfo]);
   }
 }];  
Run Code Online (Sandbox Code Playgroud)

如果执行没有错误,返回0个对象,并且仪表板显示有应该返回的对象,那么类名一定是错误的。因此,请仔细检查类名,例如拼写。

如果返回对象,则您的过滤器一定是错误的。你for在任何地方都是错误的,有两个原因:
1)for循环被执行了follows.count-次,但它总是执行相同的指令,因为index没有使用。我猜你想写(但这也是错误的

 for (i = 0; i < [follows count]; i++) {
        [query whereKey:@"Session" containedIn:follows[i]];
 }  
Run Code Online (Sandbox Code Playgroud)

2)这是错误的,因为你只能有一个过滤器whereKey:containedIn:。正如 DevKyle 所提到的,这个单个过滤器被覆盖follows.count-1多次,并且只使用最后一个过滤器。
我猜您想要对各个过滤器进行逻辑“或”之类的操作。如果是这样,您必须展平数组,即制作NSArray *flattenedFollows中所有元素的单个数组follows[i],请参阅此处并设置单个过滤器

 [query whereKey:@"Session" containedIn: flattenedFollows];  
Run Code Online (Sandbox Code Playgroud)

编辑:
最后一个想法:如果您的查询是正确的(除了 for 循环)并且没有返回任何对象,则可能是您无权访问它们。因此,请检查这些记录的 ACL 字段是否具有正确的访问权限。