gpt4 book ai didi

ios - - Collection View :viewForSupplementaryElementOfKind:atIndexPath: not called

转载 作者:行者123 更新时间:2023-11-28 08:50:21 28 4
gpt4 key购买 nike

我通过以下方式设置标题大小:

if let flowLayout = self.myCollectionView.collectionViewLayout as? UICollectionViewFlowLayout
{
flowLayout.headerReferenceSize = CGSizeMake(self.myCollectionView.frame.size.width, 250)
}

Collection View 确实显示了 header 空间,但 header 没有显示,应该创建它的函数也没有被调用。

func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView
{
let reusableView = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionHeader, withReuseIdentifier: NSStringFromClass(FeedHeader), forIndexPath: indexPath)

...

return reusableView
}
  • 该函数位于其余的 UICollectionViewDataSource 函数中

enter image description here

最佳答案

我知道有点晚了,但似乎您缺少实际添加 header ,无论是在 IB 中还是使用以下两种方法之一在代码中注册它:

func registerClass(_ viewClass: AnyClass?, forSupplementaryViewOfKind elementKind: String, withReuseIdentifier identifier: String)
func registerNib(_ nib: UINib?, forSupplementaryViewOfKind kind: String, withReuseIdentifier identifier: String)

关于ios - - Collection View :viewForSupplementaryElementOfKind:atIndexPath: not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34413903/

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