Couple of things..
In your PhotoCell
class - declare a public property:
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
Then in your PhotoCell xib
(I assume this is where you're creating it from?) connect it to the IBOutLet
you created.
I think you're doing something wrong in your cellForItemAtIndexPath
- as your error shows an instance of UICollectionViewCell
doesn't respond to cell.imageView.image = imageForCollection;
Make sure your cell identifier is also the same as you put it in your storyboard / xib file
Rewrite your cellForItemAtIndexPath
method like this:
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;{
PhotoCell *cell = [ self.photoCollectionView dequeueReusableCellWithReuseIdentifier:@"CORRECT CELL IDENTIFIER HERE" forIndexPath:indexPath];
NSDictionary *currentPhotoDict = [imageArray objectAtIndex:indexPath.row];
UIImage *imageForCollection = [UIImage imageWithData:[currentPhotoDict objectForKey:@"DImage"]];
cell.imageView.image = imageForCollection;
return cell;
}
Edit
It seems like you created a subclass of UICollectionViewCell
and never created a xib
file for it. Since you're not using storyboards do this:
In Xcode:
Create a new file - select "User Interface
" from the left under 'iOS'
and select "empty"
from the selection it shows you.
After creating your xib
file - go to it and delete UIView
that is there. Then from the object library on your right, look for UICollectionView Cell
and drag it onto the view and then drag a UIImageView
and place it in your UICollectionView cell.
Now select UICollectionViewCell
you just created and set its class to the PhotoCell
class. Connect your IBOutlets
like above.
Make sure to set the 'Reusable Cell
' attribute too. Its important here.
Then in the viewController
that loads your UICollectionView
- add this to viewDidLoad
[photoCollectionView registerNib:[UINib nibWithNibName:@"THE XIB FILE NAME YOU JUST CREATED eg: PhotoCell" bundle:nil] forCellWithReuseIdentifier:@"REUSE IDENTIFIER HERE"];
This should help you.