首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不能将NSObject -() Classname类型的值赋值给uicollectionviewdelegate委托类型

不能将NSObject -() Classname类型的值赋值给uicollectionviewdelegate委托类型
EN

Stack Overflow用户
提问于 2017-04-05 08:02:49
回答 1查看 714关注 0票数 0

我正在使用视图并在其中实现一个集合视图。

当我试图引用数据源并委托给我的colelctionview时,它会出错。

我的ClassFile

代码语言:javascript
复制
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

任何帮助都将成为学徒。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-05 08:09:57

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

代码语言:javascript
复制
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

}()

这应该能行

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43225309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档