2014-12-31 7 views
5

한 섹션에 대해서만 바닥 글보기를 표시하려면 어떻게합니까?UICollectionView 마지막 단의 바닥 글 만 표시

내가 알기로, 다른 섹션에서 바닥 글보기를 숨기려면 nil을 전달할 수 없으므로 충돌이 발생합니다.

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { 

     var v : UICollectionReusableView! = nil 
     if kind == UICollectionElementKindSectionHeader { 
      let x = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier:reuseHeaderIdentifier, forIndexPath:indexPath) as HouseNameReusableView 

      let h = houses[indexPath.section]   
      x.nameLabel.text = h["name"] as? String 

      return x 

     }else if kind == UICollectionElementKindSectionFooter { 
      if indexPath.section == houses.count - 1{ 
      let x = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier:reuseFooterIdentifier, forIndexPath:indexPath) as FooterCollectionReusableView 

      return x 
      } 
     } 
     return v 
    } 

답변

13

당신은 다른 글보기에 nil을 통과 할 수는 없지만 다른 바닥 글보기 똑같은 금액 제로 높이를 제공 할 수 있습니다 - 그들은 표시되지 않습니다, 그들은 더 높이가 없기 때문입니다.

그래서 실제로 보려는 것을 제외하고 모든 바닥 글에 0 높이를 부여하려면 collectionView:layout:referenceSizeForFooterInSection:을 구현하십시오.