2016-07-17 95 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