의 섹션에 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]것입니다.