[UICollectionViewCell imageView]: unrecognized selector posted to instance

I am trying to use a collection view and display static images in it, but I am getting the following error:

[UICollectionViewCell imageView]: unrecognized selector posted to the instance.

I configured the 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 code sscollectionViewCell.h

@interface SSCollectionViewCell : UICollectionViewCell

@property (weak) IBOutlet UIImageView *imageView;

@end

      

here is the code SSColletionViewCell.m

#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 anyone suggest where I went wrong.?

+3


source to share


3 answers


Change

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

      



For

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

      

+10


source


You missed this in the ViewDidLoad method



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

+2


source


Your cell is still a UICollectionCell and not your custom SSCollectionViewCell, there is no known message for this (unrecognized selector).

Look in the table, make sure you select the Cell collection and change its class (third tab in the right menu), put it in CustomClass now.

0


source







All Articles