I am trying to create a simple gallery for an iOS application. I'm working with a UICollectionView inside of a ViewController. Everything seems to be working fine, but I can't get the image I'm trying to use to display inside of the collection view cell. I will just dump some code here, I have been desperate to find a solution but nothing seems to work.
This is the gallery.m file:
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView;
{
//just a random value for testing
return 2;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection: (NSInteger)section
{
//another random test value
return 5;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"customCell";
customCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier
forIndexPath:indexPath];
//UIImage *image = [dataArray objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"skull.png"];
//I tried all of the below code to get the image to show but nothing seemed to work
//[cell.imageView setImage:[UIImage imageNamed:@"skull.png"]];
//[cell.imageView setNeedsDisplay];
//[cell.imageView reloadInputViews];
return cell;
}
This is the customCell.h file (the UIImageView outlet is connected to the image view inside of the collection view cell):
#import <UIKit/UIKit.h>
@interface customCell : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@end
Concerning the connections in the storyboard everything should be fine, also it would be difficult to show here but I will try to explain anyways. The UICollectionView is connected in the gallery.h file like so:
@interface gallery : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@end
The collection view cell in the storyboard has the custom class "customCell" and identifier "customCell".
If anybody could point me to where my mistake could be it would be awesome! Thank you!