Usuwanie pustego miejsca, jeśli nagłówek sekcji jest ukryty w UICollectionView

Mam dwie sekcjeUICollectionView. Chcę pokazać nagłówek sekcji wUICollectionView tylko dla pierwszej sekcji. Nie w sekcji 0.

Więc próbowałem wrócićnil wviewForSupplementaryElementOfKind: metoda dlasection == 0 i zwraca widok dlasection == 1.

Zawiesza się i wyświetla następujący błąd:

Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes]:

Oto mój kod do widoku dodatkowego.

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *sectionHeader = nil;
    if (kind == UICollectionElementKindSectionHeader && indexPath.section == 1) {
        sectionHeader = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"EventSectionHeader" forIndexPath:indexPath];
        sectionHeader.layer.borderWidth = .5f;
        sectionHeader.layer.borderColor = [UIColor colorWithRed:221.0 / 255.0 green:223.0 / 255.0 blue:220.0 / 255.0 alpha:1.0].CGColor;
    }

    return sectionHeader;
}

Znalazłem, że wracam zeroviewForSupplementaryElementOfKind: metoda upada dla innych. Inne odpowiedzi sugerujące usunięcie tej metody.

Ale chcę pokazać nagłówek sekcji tylko dla określonych sekcji. Jak uzyskać ten zwrotny widok tylko dla jednej sekcji? Dzięki. Każda pomoc byłaby doceniana.

EDYTOWAĆ:

Jak powiedział @san, zaktualizowałem kod, aby ukryć nagłówek sekcji. To działa. Ukrywa nagłówek. Ale nadal widzę puste miejsce w miejscu nagłówka sekcji. Oczekiwane wyniki to brak miejsca na nagłówek sekcji, jeśli jest ukryty.

zaktualizowany kod:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{

    UICollectionReusableView *sectionHeader = nil;
    if (kind == UICollectionElementKindSectionHeader) {
        sectionHeader = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"EventSectionHeader" forIndexPath:indexPath];
        sectionHeader.layer.borderWidth = .5f;
        sectionHeader.layer.borderColor = [UIColor colorWithRed:221.0 / 255.0 green:223.0 / 255.0 blue:220.0 / 255.0 alpha:1.0].CGColor;
        if (indexPath.section == 0) {
            sectionHeader.hidden = YES;

        }else {
            sectionHeader.hidden = NO;
        }
    }

    return sectionHeader;
}

Próbowałem nawet ustawić ramkę dla sectionHeader, jak powiedział @san. Ale nie ma szczęścia. ten sam wynik.

questionAnswers(5)

yourAnswerToTheQuestion