在Swift 2.3 App中未调用的UICollectionViewDelegateFlowLayout方法

我没有调用任何UICollectionViewDelegateFlowLayout方法.有人可以帮我找到解决方案吗?

在我的ViewDidLoad方法中,我为集合视图设置了委托和数据源
self.collectionView.delegate = self和
self.collectionView.dataSource = self

这是我的委托方法

func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,insetForSectionAt section: Int) -> UIEdgeInsets {
    let deviceidiom = UIScreen.mainScreen().traitCollection.userInterfaceIdiom
    switch(deviceidiom){
    case .Phone:

        return UIEdgeInsets(top: 50,left: 10,bottom: 0,right: 10)
    case .Pad:
        return UIEdgeInsets(top: 60,left: 20,right: 20)
    default:
        break
    }
}

func collectionView(collectionView: UICollectionView,minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
    return CGFloat(8)
}

func collectionView(collectionView: UICollectionView,sizeforItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

    let deviceidiom =          UIScreen.mainScreen().traitCollection.userInterfaceIdiom

    switch(deviceidiom){
    case .Phone:

        let cellWidth = (view.bounds.size.width - 16) / 2
        let cellHeight = cellWidth
     return CGSize(width: cellWidth,height: cellHeight)

    case .Pad:

        let cellWidth = (view.bounds.size.width - 40) / 2
        let cellHeight = cellWidth
        return CGSize(width: cellWidth,height: cellHeight)

    default:
        break
    }
}

我的ViewDidLoad方法

override func viewDidLoad(){
        super.viewDidLoad()

self.collectionView.dataSource = self
 self.collectionView.delegate = self
    cellImages = [
        "contact.png","share.png","setting.png","logout.png"]
    cellLabels = [
        "Contact","Share","Setting","logout"]

    self.view.backgroundColor = uicolorFromHex(0xE5DADA)

    self.collectionView?.backgroundColor = uicolorFromHex(0xE5DADA)
    self.navigationController?.navigationBarHidden = false
    self.navigationItem.hidesBackButton = true
    navigationController!.navigationBar.titleTextAttributes =
        [NSForegroundColorAttributeName: UIColor.whiteColor()]
    navigationController!.navigationBar.barTintColor = UIColor(red: 0.0431,green: 0.0824,blue: 0.4392,alpha: 1.0)

    if let user = User.currentUser(){
    if(user.manager){
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Board",style: UIBarButtonItemStyle.Plain,target: self,action: #selector(goToBoard))

}

谢谢,

解决方法

我终于通过创建我的课程的扩展来解决这个问题  MainViewController:UICollectionViewDelegateFlowLayout {},将所有委托方法放在那里并清理构建.它在Swift 3中运行属性(在同一类中),但对于swift 2.3,由于某些奇怪的原因,它需要被扩展.谢谢,

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...