Reputation: 233
i have everything working it seems, but i noticed sometimes when i go to the collection view, its blank, but when i refresh it, everything is loaded and shown.
here is my cellForItemAtIndexPath
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString * const reuseIdentifier = @"imageCell";
imageCollectionCell *cell = [self.myCollectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
// Configure the cell
PFFile *imageFile = [imageObject objectForKey:@"image"];
[imageFile getDataInBackgroundWithBlock:^(NSData * _Nullable data, NSError * _Nullable error) {
if (!error) {
cell.imageViewCell.image = [UIImage imageWithData:data];
cell.imageViewCell.contentMode UIViewContentModeScaleAspectFill;
}
else{
NSLog(@"Fail");
}
} progressBlock:^(int percentDone) {
}];
return cell;
}
here is my query for the collectionview
- (void) queryData {
imageCollectionCell *cell = (imageCollectionCell *)[self.myCollectionView cellForItemAtIndexPath:[[self.myCollectionView indexPathsForSelectedItems] firstObject]];
cell.imageViewCell.image = nil;
NSLog(@"initiated");
[self.refreshControl endRefreshing];
PFObject *queryPhotos = self.userInformationObject;
PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
[query whereKey:@"userTookPhoto" equalTo:queryPhotos];
[query orderByAscending:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error)
{
if (!error) {
NSLog(@"Query no error");
imageFilesArray = [[NSArray alloc] initWithArray:objects];
}
}];
[self.myCollectionView reloadData];
}
Upvotes: 0
Views: 119
Reputation: 2048
When you reload your collection view, you can't know if data are loaded.
So you must put your reload data in the completion block.
Upvotes: 2