2016-11-08 79 views
0

我有一個集合視圖,需要顯示不同類型的標頭,具體取決於我的集合視圖的哪個節。取決於集合視圖中的節的不同節標題

但是,當我將第二個可重用視圖添加到故事板時,它會自動將其視爲我的頁腳視圖。

有沒有什麼辦法可以讓我的收藏視圖有兩個不同的節標題?

回答

0

您將不得不以編程方式以編程方式執行dequeueheaderView。像下面的東西會幫助你:

override func collectionView(_ collectionView: UICollectionView, 
         viewForSupplementaryElementOfKind kind: String, 
         at indexPath: IndexPath) -> UICollectionReusableView { 

    switch kind { 
    case UICollectionElementKindSectionHeader: 
     var headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, 
        withReuseIdentifier: "HeaderOne", 
        for: indexPath) as! HeaderOneView 
     if sectionTwo { 
      headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, 
        withReuseIdentifier: "HeaderTwo", 
        for: indexPath) as! HeaderTwoView 
     } 

     return headerView 
    default: 
     assert(false, "Unexpected element kind") 
    } 
} 

你也可能需要使用此functionregister(_:forSupplementaryViewOfKind:withReuseIdentifier:)註冊一個通過storyboard沒有創建的視圖。

相關問題