OGeek|极客世界-中国程序员成长平台

标题: ios - 无法将页脚添加到 Collection View [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:41
标题: ios - 无法将页脚添加到 Collection View

我只需要一个高度为 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 。我无法理解为什么这不起作用以及我应该如何纠正这个问题。请帮我纠正这个问题。



Best Answer-推荐答案


这是我的方式。我对此进行了测试,它可以工作。

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4