我正在使用视图并在其中实现一个集合视图。
当我试图引用数据源并委托给我的colelctionview时,它会出错。
我的ClassFile
class MenuBar : UIView, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout{
let collectionView : UICollectionView = {
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.backgroundColor = UIColor.rgb(red: 230, green: 32, blue: 31)
cv.delegate = self // Error here
return cv
}()
override init(frame: CGRect){
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}}
我不能将委托和数据源授予我的集合视图,我还实现了以下两种方法
cellForItemAt indexPath numberOfItemsInSection
任何帮助都将成为学徒。
发布于 2017-04-05 08:09:57
这是因为你试图在封闭中访问自我
lazy var collectionView : UICollectionView = {
[unowned self] in
let layout = UICollectionViewFlowLayout()
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
cv.backgroundColor = UIColor.rgb(red: 230, green: 32, blue: 31)
cv.delegate = self // Error here
return cv
}()这应该能行
https://stackoverflow.com/questions/43225309
复制相似问题