简体   繁体   English

Inheritance 来自非协议类型 'UICollectionViewFlowLayout'

[英]Inheritance from non-protocol type 'UICollectionViewFlowLayout'

I have a horizontal collection view in my project which has 2 elements - a button and a label. Button and label are stuck to each other and then I want to show other button and label within the cell with space between 2 elements ie Button 1 and label 1, then some space and then display button 2 and label 2. Want to have some space between label 1 and button 2.我的项目中有一个水平集合视图,它有 2 个元素 - 一个按钮和一个 label。按钮和 label 相互粘在一起,然后我想在单元格内显示其他按钮和 label,两个元素之间有空间,即按钮 1 和label 1,然后一些空间,然后显示按钮2和label 2。希望label 1和按钮2之间有一些空间。

I came across some 'UICollectionViewFlowLayout' related methods and did try adding the code for it to test, but the functions are not getting called.我遇到了一些与“UICollectionViewFlowLayout”相关的方法,并尝试添加代码进行测试,但这些函数没有被调用。 Below are the functions:以下是功能:

extension MyController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewFlowLayout {
       func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 50
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 100
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 100, bottom: 100, right: 100)
    }
}

However adding 'UICollectionViewFlowLayout' is giving me "Inheritance from non-protocol type 'UICollectionViewFlowLayout'" error.但是,添加“UICollectionViewFlowLayout”会给我"Inheritance from non-protocol type 'UICollectionViewFlowLayout'"错误。

How can I get 'minimumLineSpacingForSectionAt' and other methods executed?如何执行“minimumLineSpacingForSectionAt”和其他方法? Or how can I add space between label 1 and button 2, and then space between label 2 and button 3?或者如何在 label 1 和按钮 2 之间添加空格,然后在 label 2 和按钮 3 之间添加空格?

It is UICollectionViewDelegateFlowLayout它是UICollectionViewDelegateFlowLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM