从几个类中解析提取对象返回0(iOS)

时间:2016-01-03 14:33:59

标签: ios objective-c cocoa-touch parse-platform

我正在尝试同时从几个类中获取对象,但除了1个返回0个对象之外的所有对象。 我真的不知道该怎么做。

我的代码:

PFQuery *query=[PFQuery queryWithClassName:@"Dogs"];
query.limit=1000;
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }
    self.dogs=[[NSArray alloc] initWithArray:objects];
}];

query=[PFQuery queryWithClassName:@"Cats"];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }

    self.cats=[[NSArray alloc] initWithArray:objects];
}];

query=[PFQuery queryWithClassName:@"Mice"];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }
    self.mice=[[NSArray alloc] initWithArray:objects];
}];

query=[PFQuery queryWithClassName:@"Elephants"];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }
    self.elephants=[[NSArray alloc] initWithArray:objects];
}];

query=[PFQuery queryWithClassName:@"Lions"];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }
    self.lions=[[NSArray alloc] initWithArray:objects];
}];

有人知道为什么会这样吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

你应该对PFQuery使用不同的引用 - -

PFQuery *query1=[PFQuery queryWithClassName:@"Dogs"];
query1.limit=1000;
[query1 findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }
    self.dogs=[[NSArray alloc] initWithArray:objects];
}];

PFQuery query2=[PFQuery queryWithClassName:@"Cats"];
[query2 findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }

    self.cats=[[NSArray alloc] initWithArray:objects];
}];

PFQuery query3=[PFQuery queryWithClassName:@"Mice"];
[query3 findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }
    self.mice=[[NSArray alloc] initWithArray:objects];
}];

PFQuery query4=[PFQuery queryWithClassName:@"Elephants"];
[query4 findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }
    self.elephants=[[NSArray alloc] initWithArray:objects];
}];

PFQuery query5=[PFQuery queryWithClassName:@"Lions"];
[query5 findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
    if (error) {
        NSLog(@"Error: %@",[error description]);
    }
    self.lions=[[NSArray alloc] initWithArray:objects];
}];