Я пытаюсь адаптировать использование UICollectionViewController, который я заполняю массивом локальных изображений, чтобы получить изображения из Parse.
Пока это довольно просто. Мой NSArray много раз заполняется одним и тем же локальным образом:
testImages = [NSArray arrayWithObjects: @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @" thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail.jpg", @"thumbnail .jpg", @"thumbnail.jpg", @"thumbnail.jpg", nil];
В collectionView:cellForItemAtIndexPath: я настраиваю свою ячейку (из раскадровки):
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// Set up cell identifier that matches the Storyboard cell name
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
// Configure the cell to show photo thumbnail
UIImageView *testImageView = (UIImageView *)[cell viewWithTag:100];
testImageView.image = [UIImage imageNamed:[testImages objectAtIndex:indexPath.row]];
return cell;
}
Это работает и выглядит так:
Что я пытаюсь сделать, так это заменить локально созданный массив изображениями, которые я получаю из своего класса Photo в Parse.
Я пытаюсь сделать это с помощью метода viewDidLoad:
PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
PFUser *user = [PFUser currentUser];
[query whereKey:@"user" equalTo:user];
[query orderByAscending:@"createdAt"];
[query setCachePolicy:kPFCachePolicyNetworkOnly];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %d photos.", objects.count);
testImages = [NSMutableArray arrayWithArray:objects];
NSLog(@"# Images: %d", [testImages count]);
// Do something with the found objects
for (PFObject *object in objects) {
NSLog(@"Object Name: %@", object.objectId);
}
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
Дело в том, что я каждый раз получаю пустой массив. Я предполагаю, что, поскольку это выполняется в блоке в фоновом режиме, как только collectionView:numberOfItemsInSection: запрашивает количество элементов в массиве «testImages», я всегда получаю 0 элементов.
Когда UICollectionViewController хочет использовать информацию из массива для заполнения ячеек, там ничего нет.
Я не знаю, размещаю ли я свой код в неправильном месте или использую неправильный запрос.
Вы можете получить мою ошибку здесь?
Любая обратная связь будет принята с благодарностью.