2016-07-17 97 views
0

我已經在故事板中創建了UICollectionViewController以及集合視圖的標題。自定義UICollectionViewLayout標題和故事板

我正在使用名爲CHTCollectionViewWaterfallLayout的第三方UICollectionViewLayout。當collectionView(_:viewForSupplementaryElementOfKind:atIndexPath:)被稱爲頭,kindCHTCollectionElementKindSectionHeader而不是UICollectionElementKindSectionHeader和程序崩潰,並告訴我我沒有註冊一個類爲CHTCollectionElementKindSectionHeader。說得通。但是,如果我以編程方式爲CHTCollectionElementKindSectionHeader註冊一個班級,我不會從故事板中獲益,因爲程序在初始化標題時將調用initWithFrame:而不是initWithCoder

有沒有什麼辦法可以解決這個問題,我可以以某種方式使用我在故事板中創建的CHTCollectionElementKindSectionHeader

+0

的OBJ-C的夫特? – Konsy

+0

我在swift中寫過它,但是知道在實現(而不是語法)方面是否存在巨大差異。 – theNotSoPro

回答

0

我有一個非常類似的問題今天發現我有我的頭單元變更登記從:

collectionView.registerClass(
    UICollectionReusableView.self, 
    forSupplementaryViewOfKind: UICollectionElementKindSectionHeader,  
    withReuseIdentifier: headerId 
) 

collectionView.registerClass(
    UICollectionReusableView.self, 
    forSupplementaryViewOfKind: layout.CHTCollectionElementKindSectionHeader, 
    withReuseIdentifier: headerId 
) 

希望這是有幫助的,我一直在打我的頭靠在牆上幾個小時,當我自己尋求幫助時,我才發現你的問題。

:佈局以上定義這樣let layout = CHTCollectionViewWaterfallLayout()

+0

嘿謝謝你的回覆。是的,你需要註冊'CHTCollectionElementKindSectionHeader'才能運行。然而,我的頭文件已經設計在故事板中,如果我以編程方式註冊類,就像調用'initWithFrame'而不是'initWithCoder'。 'initWithFrame'沒有看故事板中設計的內容,不幸的是... – theNotSoPro

+0

對不起,我誤讀了那一點。真的很抱歉,我沒有幫助 –

+0

沒問題。感謝您的嘗試。 – theNotSoPro