Опитвам се да адаптирам използването на 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", нула];
В collectionView:cellForItemAtIndexPath: настройвам клетката си (от Storyboard):
- (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 Class в 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 иска да използва информацията от масива, за да попълни клетките, там няма нищо.
Не знам дали поставям кода си на грешното място или използвам грешна заявка.
Можете ли да разберете грешката ми тук?
Всякакви отзиви ще бъдат много оценени.