Я хочу, щоб мої розділи в UICollectionViewмали заголовок із зображенням.
Я виконав ці кроки:
- на раскадровці, призначив заголовок як аксесуар для мого
UICollectionView - дав йому ідентифікатор
- створив підклас
UICollectionReusableViewдля нього - призначив користувацький клас класу на розкадруванні.
- покладіть
ImageViewу заголовку аксесуар - зробив вихід для
ImageViewспеціального класу у.hфайлі - Реалізовано наступне на
viewDidLoad:
[self.collectionView registerClass:[ScheduleHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier];
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionHeader)
{
ScheduleHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerIdentifier forIndexPath:indexPath];
headerView.headerImageView.image = [UIImage imageNamed:@"blah.png"];
reusableview = headerView;
}
return reusableview;
}
Я знаю, що методи джерела даних та делегатів працюють, оскільки я бачу всі комірки та його розділи. Однак у мене немає своїх заголовків. Я вказав точку зупинки за вищенаведеним методом, і його ніколи не викликають.
Що я роблю не так?
kind == UICollectionElementKindSectionHeaderзамість вмісту рядків, напевно, ви хочете використовувати їх[kind isEqualToString: UICollectionElementKindSectionHeader].