Я создал UICollectionView в раскадровке и добавил представление нижнего колонтитула заголовка, которое работает нормально. Но мой вопрос заключается в том, как создать представление UICollectionViewReusable для добавления в качестве SupplementaryView программно. Я пробовал, но делегаты не вызываются. Обратите внимание, что я также установил делегат. пытался
- (void)setUpCustomCollectionView
{
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40, 320, 500) collectionViewLayout:layout];
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"brandingHeaderView"];
self.collectionView.bounces = NO;
self.collectionView.tag = 10;
self.collectionView.backgroundColor = [UIColor darkGrayColor];
[self.collectionView setDataSource:self];
[self.collectionView setDelegate:self];
self.collectionView.dataSource=self;
self.collectionView.delegate=self;
[self.baseScrollView addSubview:self.collectionView];
}
И в делегате
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath
{
if (kind == UICollectionElementKindSectionHeader) {
UICollectionReusableView *headerView = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"brandingHeaderView" forIndexPath:indexPath];
UIView * view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 80)];
view.backgroundColor = [UIColor redColor];
[headerView addSubview:view];
return headerView;
}
}
веди меня.