gpt4 book ai didi

ios - 自定义 UICollectionViewLayout 标题和 Storyboard

转载 作者:行者123 更新时间:2023-11-30 13:14:07 26 4
gpt4 key购买 nike

我在 Storyboard中创建了一个 UICollectionViewController 以及 Collection View 的标题。

我正在使用名为 CHTCollectionViewWaterfallLayout 的第三方 UICollectionViewLayout。当为 header 调用 collectionView(_:viewForSupplementaryElementOfKind:atIndexPath:) 时,kindCHTCollectionElementKindSectionHeader 而不是 UICollectionElementKindSectionHeader程序崩溃并告诉我没有为 CHTCollectionElementKindSectionHeader 注册类。说得通。但是,如果我以编程方式为 CHTCollectionElementKindSectionHeader 注册一个类,我就无法从 Storyboard 中受益,因为程序在初始化 header 时会调用 initWithFrame: 而不是 initWithCoder

有没有办法解决这个问题,我可以以某种方式使用我在 Storyboard中为 CHTCollectionElementKindSectionHeader 创建的内容?

最佳答案

我今天遇到了非常类似的问题,发现我必须更改标题单元格注册:

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

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

希望这对您有所帮助,我已经在墙上撞了几个小时了,我只是在自己寻求帮助时才发现您的问题。

注意:上面定义的布局如下 let layout = CHTCollectionViewWaterfallLayout()

关于ios - 自定义 UICollectionViewLayout 标题和 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38424324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com