2013-09-22 12 views
3

我正在使用Parse for iOS應用程序,它需要我在一個PFObject中加載多個圖像,因此我在該對象中有多個PFFiles。我知道你必須單獨加載每個對象才能使用它,但是有沒有辦法從對象中一次加載多個PFFile?任何輸入是讚賞!如何從Xcode中加載多個PFFiles

回答

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 [email protected]"); 
     } 
    }]; 

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

}]; 
+0

非常感謝!那解決了我的問題= D –

+0

這還真發2個查詢拉2個文件吧?有沒有辦法只有這一個查詢?因爲你知道解析對查詢計數有限制 – Esqarrouth

+1

正確,這是2個查詢。從非技術角度來看當我開發一個應用程序時,我花了大量的時間來儘量減少我的分析查詢計數。最後,查詢計數是相當不錯的,而回過頭來看,花在吸引更多用戶或實現額外功能上的時間會更好。 – ardrian

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 [email protected]"); 
     } 
    }]; 

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

}]; 
+0

這還是實際發送2個查詢拉2個文件吧?有沒有辦法只有這一個查詢?因爲你知道解析有查詢計數的限制 – Esqarrouth

+1

@Esq我還沒有找到方法拉1個查詢的2個文件。 – tmr