gpt4 book ai didi

ios - 无法将页脚添加到 Collection View

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:01:10 26 4
gpt4 key购买 nike

我只需要一个高度为 50 且背景颜色为黑色的页脚。而已。暂时忘记下面的实现,让我知道您将如何实现相同的实现。

我正在使用以下内容:

enter image description here

enter image description here

enter image description here enter image description here

 func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "FooterView", for: indexPath as IndexPath)
// configure footer view
return view
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize
{
return CGSize(width: 375, height: 100)
}

但是,没有页脚附加到 Collection View 。我无法理解为什么这不起作用以及我应该如何更正它。请帮助我更正此问题。

最佳答案

这是我的方式。我对此进行了测试,它有效。

class ViewController: UIViewController, UICollectionViewDataSource {

@IBOutlet weak var collectionView: UICollectionView!

override func viewDidLoad() {
super.viewDidLoad()
collectionView.dataSource = self
}

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

let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "Footer", for: indexPath)
view.backgroundColor = .red
return view
}
}

关于ios - 无法将页脚添加到 Collection View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52835604/

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