title: Removing empty space, if the section header is hidden in the UICollectionView
body: <p>I have two sections in <code>UICollectionView</code>. I want to show a section header in <code>UICollectionView</code> for only 1st section. Not in 0th section.</p>
  
  <p>So I tried to return <code>nil</code> in <code>viewForSupplementaryElementOfKind</code>: method for <code>section == 0</code> and returns view for the <code>section == 1</code>.</p>
  
  <p>It crashes and shows below error:</p>
  
  <pre><code>Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes]:
  </code></pre>
  
  <p>Here it is my code for the supplementary view.</p>
  
  <pre><code>- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  {
      UICollectionReusableView *sectionHeader = nil;
      if (kind == UICollectionElementKindSectionHeader &amp;&amp; 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;
  }
  </code></pre>
  
  <p>I have found that returning nil in <code>viewForSupplementaryElementOfKind:</code> method crashing for others too. Other answers suggesting to remove that method. </p>
  
  <p>But I want to show section header for specific sections only. How to achieve that returning view for only one section? Thanks. Any help would be appreciated.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>As @san said, I have updated code to hide the section header. It works. It hides the header. But I am still seeing the empty space in the place of section header. Expected results is there should be no space for section header, if it is hidden.</p>
  
  <p><strong>updated code:</strong></p>
  
  <pre><code>- (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;
  }
  </code></pre>
  
  <p><strong>I even tried setting the frame for sectionHeader as @san said. But no luck. same result.</strong></p>