如何在Xcode中从Parse加载多个PFF

时间:2013-09-22 04:05:09

标签: ios xcode parse-platform

我正在使用Parse作为iOS应用程序,它要求我在一个PFObject中加载多个图像,因此我在该对象中有多个PFFiles。我知道你必须单独加载每个对象才能使用它,但有没有办法从一个对象一次加载多个PFFiles?任何意见都表示赞赏!

2 个答案:

答案 0 :(得分:2)

对于像我这样的其他新人,我相信'ahar083'中接受的答案可能会有错字。我将'data1'更改为'file1',将'data2'更改为'file2'(更新后的代码=粘贴在下面)。我没有足够的分数来评论答案=将我的评论作为新答案发布。

PFQuery *query = [PFQuery queryWithClassName:@"ManyFileClass"];
[query getObjectInBackgroundWithId:@"OBJECT_ID" 
                             block:^(PFObject *manyFileClass, NSError *error) {
    PFFile* file1 = [o objectForKey:@"file1"];
    PFFile* file2 = [o objectForKey:@"file2"];

    [file1 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            NSLog(@"Got data from file1@");
        }
    }];

    [file2 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            NSLog(@"Got data from file2@");
        }
    }];

}];

答案 1 :(得分:0)

当您检索PFObject时,实际上并没有拉下该对象中指向的任何PFFiles,您总是需要手动下拉文件,无论是1个文件还是5个文件。

PFQuery *query = [PFQuery queryWithClassName:@"ManyFileClass"];
[query getObjectInBackgroundWithId:@"OBJECT_ID" 
                             block:^(PFObject *manyFileClass, NSError *error) {
    PFFile* file1 = [o objectForKey:@"file1"];
    PFFile* file2 = [o objectForKey:@"file2"];

    [data1 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            NSLog(@"Got data from file1@");
        }
    }];

    [data2 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
            NSLog(@"Got data from file2@");
        }
    }];

}];