I've tried searching through the Stack Overflow questions related to this issue but can't seem to understand what I'm doing wrong. I have a UIView
that is an xib. I use this as a map annotation callout. I want to have a UICollectionView
inside of this callout xib. So I added a the UICollectionView
to the xib and since it doesn't allow for the adding of a cell onto the UICollectionView when its inside of a UIView
I created my own class for my cell with an xib for the cell.
I keep crashing with '*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:]'.
I currently have my UIView
as the collectionView's dataSource and delegate.
Thanks in advance.
//UIView
**MapAnnotationCallout.m File**
-(id)initWithFrame:(CGRect)frame {
//'mediaPreviewCell' is my custom cell
[_mediaCollectionView registerNib:[UINib nibWithNibName:@"MediaPreviewCell" bundle:nil] forCellWithReuseIdentifier:@"mediaCell"];
_mediaCollectionView.backgroundColor = [UIColor clearColor];
self = [super initWithFrame:frame];
if (self) {
_previewImages = [[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"belleIsle-1"], [UIImage imageNamed:@"belleIsle-2"], [UIImage imageNamed:@"old_english_D"], nil];
[[NSBundle mainBundle]loadNibNamed:@"MapAnnotationCalloutView" owner:self options:nil];
self.bounds = _view.bounds;
[self addSubview:_view];
}
return self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [_previewImages count];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(80, 80);
}
- (MediaPreviewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
*******crashing on this line with exception breakpoint************
MediaPreviewCell *cell = [_mediaCollectionView dequeueReusableCellWithReuseIdentifier:@"mediaCell" forIndexPath:indexPath];
******************************************
cell.cellImage.image = [_previewImages objectAtIndex:indexPath.item];
return cell;
}