What I have is an array of url's that point to images and a corresponding array of the names of the images
For example ['www.pictures/dog.jpg', 'www.pictures/lamp.jpg', 'www.pictures/piano.jpg'] ['dog', 'lamp', 'piano']
I want each cell to have a the picture with the corresponding word. My problem is that the pictures almost always appear out of order. How I have it now, the words appear in order.
Anyone have an idea of how to get my images appear in order
- (photoCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
photoCollectionViewCell *photoCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"photoCell" forIndexPath:indexPath];
if(self.photoIndex == (self.totalPhotos)) {
self.photoIndex = 0;
}
NSURL *url = [NSURL URLWithString:self.imageURLArray[self.photoIndex]];
NSString *word = self.phraseWordsArray[self.photoIndex];
photoCell.photoImageView.image = [UIImage imageNamed:@"icn_default"];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
photoCell.photoImageView.image = image;
photoCell.photoLabel.text = word;
});
});
self.photoIndex++;
return photoCell;
}