无法指定类型的NSObject的价值 - ()类名键入uicollectionviewdelegate

问题描述:

我使用视图和执行的CollectionView进去无法指定类型的NSObject的价值 - ()类名键入uicollectionviewdelegate

当我试图引用的数据源和委托给我的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") 
} 

}

我不能给委托和数据源到我的CollectionView 种我已经实现了以下两种方法也

cellForItemAt indexPath numberOfItemsInSection

任何帮助将appriciated

+0

'类的MenuBar:UIView'其一个视图中未'类的MenuBar:UIViewController' –

这是因为你试图访问自我封闭物

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 

}() 

这应该工作

+0

谢谢@Evgeniy Gushchin –