本文主要是介绍swift collectionView不走代理方法原因,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
最近写swift项目的时候利用懒加载方式加载collectionview,因为没有特殊的要求,就简单些了代码如下:
private lazy var collectionView:UICollectionView = {let layout = UICollectionViewLayout.init()let collectionView = UICollectionView.init(frame: .zero, collectionViewLayout: layout)collectionView.delegate = selfcollectionView.dataSource = selfcollectionView.backgroundColor = UIColor.whitecollectionView.showsVerticalScrollIndicator = falsecollectionView.showsHorizontalScrollIndicator = falsecollectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: UICollectionViewCellID)return collectionView}()
一眼看去没啥问题,但是运行起来就不走代理方法,也没有报错,一时懵逼。
再仔细看了代码发现把代码写错了:
把UICollectionViewFlowLayout写成了UICollectionViewLayout
修改回来就好了!记录一下,希望能帮助到你
END.
这篇关于swift collectionView不走代理方法原因的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!