Reputation: 5777
on an UICollectionView I want to populate the CollectionViewCell with images. But I get the following Error:
Where is my error and how can I fix it?
2013-01-29 22:25:38.606 foobar[1277:c07] CollectionViewController loaded with searches: 22
2013-01-29 22:25:38.609 foobar[1277:c07] id: 0 -> content: <UIImage: 0xaa618e0>
2013-01-29 22:25:38.610 foobar[1277:c07] -[UICollectionViewCell cellImageView]: unrecognized selector sent to instance 0x939a7b0
2013-01-29 22:25:38.610 foobar[1277:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UICollectionViewCell cellImageView]: unrecognized selector sent to instance 0x939a7b0'
*** First throw call stack:
(0x1d9f012 0x139fe7e 0x1e2a4bd 0x1d8ebbc 0x1d8e94e 0x478a 0x7e9a1a 0x7eb034 0x7ed2d1 0x33792d 0x13b36b0 0x2afffc0 0x2af433c 0x2af4150 0x2a720bc 0x2a73227 0x2a738e2 0x1d67afe 0x1d67a3d 0x1d457c2 0x1d44f44 0x1d44e1b 0x1cf97e3 0x1cf9668 0x2e765c 0x24dd 0x2405)
libc++abi.dylib: terminate called throwing an exception
(lldb)
The code which causes the error is following:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CollectionViewCell *myCell = (CollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:Cellid forIndexPath:indexPath];
int row = [indexPath row];
NSLog(@"id: %d -> content: %@", row, [self.searches objectAtIndex:row]);
myCell.cellImageView.image = self.searches[row]; // <-- Signal SIGABRT
return myCell;
}
The code for UICollectionViewCell is the following:
#import <UIKit/UIKit.h>
@interface CollectionViewCell : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UIImageView *cellImageView;
@end
#import "CollectionViewCell.h"
@implementation CollectionViewCell
@synthesize cellImageView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end
Upvotes: 1
Views: 7266
Reputation: 31304
When you call [collectionView dequeueReusableCellWithReuseIdentifier:Cellid forIndexPath:indexPath]
you are not being returned a cell that belongs to your custom collection view cell subclass, but a standard UICollectionViewCell
. This suggests to me that maybe something is off at the point at which you register your cell with your container view. It's probably going to be helpful if you post that code as well.
Upvotes: 0
Reputation: 5777
I forgot to add the class: CollectonViewCell
to Collection View Cell in Storyboard (Identity Insepector). After that and reassigning the IBOutlet
cellImageView
it worked!
Upvotes: 1
Reputation: 1739
Please make sure, that you set the custom class CollectionViewCell
for the cell in Interface Builder.
Upvotes: 8