Chcę, aby moje sekcje UICollectionViewmiały nagłówek z obrazem.
Wykonałem następujące kroki:
- w scenorysie przypisano nagłówek jako dodatek do mojego
UICollectionView - nadał mu identyfikator
- utworzył
UICollectionReusableViewdla niego podklasę - przypisał klasę niestandardową do klasy w scenorysie.
- umieścić
ImageViewna akcesorium nagłówka - stworzył ujście dla
ImageViewklasy niestandardowej w.hpliku - Wdrożono w
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;
}
Wiem, że metody źródła danych i delegata działają, ponieważ widzę wszystkie komórki i ich sekcje. Jednak nie mam swoich nagłówków. W powyższej metodzie wstawiłem punkt przerwania i nigdy nie jest on wywoływany.
Co ja robię źle?
kind == UICollectionElementKindSectionHeaderdo ciągów zamiast zawartości łańcuchów, prawdopodobnie chcesz użyć[kind isEqualToString: UICollectionElementKindSectionHeader]zamiast tego.