Я попытался выполнить поиск по вопросам переполнения стека, относящихся к этой проблеме, но не могу понять, что я делаю неправильно. У меня есть UIView
, который является xib. Я использую это как обозначение аннотации карты. Я хочу иметь UICollectionView
внутри этой выноски xib. Поэтому я добавил UICollectionView
в xib и, поскольку он не позволяет добавлять ячейку в UICollectionView, когда ее внутри UIView
я создал свой собственный класс для своей ячейки с xib для ячейки.Добавить UICollectionView в UIView
Я продолжаю врезаться с '*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:]'.
настоящее время у меня мой UIView
в качестве DataSource и делегата CollectionView в.
Заранее спасибо.
//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;
}
Вы видели это? http://stackoverflow.com/a/12600019/5716449 – Ro4ch
@ Ro4ch Спасибо за ответ. Да. Я регистрирую nib в методе initWithFrame. – dcotter
Какое утверждение не выполняется? – matt