I am trying to use collection view and display static images in that, but I get the following error:
[UICollectionViewCell imageView]: unrecognized selector sent to instance.
I have configured cell identifire = Cell.
Here is my code:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
SSCollectionViewCell *cell = (SSCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
int imageNumber = indexPath.row % 10;
cell.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"Image%d.jpg",imageNumber]];
return cell;
}
here is the sscollectionViewCell.h code
@interface SSCollectionViewCell : UICollectionViewCell
@property (weak) IBOutlet UIImageView *imageView;
@end
here is the SSColletionViewCell.m code
#import "SSCollectionViewCell.h"
@interface SSCollectionViewCell ()
@end
@implementation SSCollectionViewCell
@synthesize imageView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end
Can any one suggest where i made mistake.?
Change
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
To
[self.collectionView registerClass:[SSCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With