こんにちは、Parse データベースからいくつかのファイルを照会しようとしています。ファイルを updateAt 時間に従ってソートしたいと考えています。次のコードがあります。クエリは機能し、結果は条件に従ってソートされますが、getDataInBackground を使用してファイルをロードしてから配列に追加すると、結果がソートされます。ファイルはソートされておらず、配列内でランダムに表示されます。
だから私の質問は
- 配列内のファイルがクエリ結果と同じ順序になっていることを確認するにはどうすればよいですか?
- getDataInBackground の完了ブロックで objectID に対してファイル/画像をチェックする方法はありますか?
ps メインスレッドをブロックしたくないので、getData を使用したくありません。
事前にどうもありがとうございました
PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
[query orderByDescending:@"updateAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *photoStacks, NSError *error)
{
if (!error) {
// The find succeeded.
for (PFObject *photoImage in photoStacks) {
PFFile *userImageFile = photoImage[@"image"];
[userImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:imageData];
// need to check object id before adding into the stack to make sure the order is right
[photoImageStacks addObject:image];
if ([photoImageStacks count] == photoStacksCount)
{
[photoPile setArray:photoImageStacks];
}
}
}];
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];