Jatin Tamakuwala
Jatin Tamakuwala

Reputation: 31

[UICollectionViewCell imageView]: unrecognized selector sent to instance

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.?

Upvotes: 3

Views: 3018

Answers (3)

thatzprem
thatzprem

Reputation: 4767

Change

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

To

[self.collectionView registerClass:[SSCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];

Upvotes: 10

Manjit Singh
Manjit Singh

Reputation: 238

You missed this in the ViewDidLoad Method

[self.collectionView registerClass:[SSCollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];

Upvotes: 2

Onik IV
Onik IV

Reputation: 5047

Your cell is still a UICollectionCell and not your custom SSCollectionViewCell, It´s for that does´t know the message (unrecognized selector).

Look in stroryboard, be sure the select the collectionCell, and change it´s class (third tab in right menu), in CustomClass put your now.

Upvotes: 0

Related Questions