ios – Swift’没有名为’的成员

ios – Swift’没有名为’的成员,第1张

概述有这个问题的解决方案吗? class ViewController : UIViewController { let collectionFlowLayout = UICollectionViewFlowLayout() let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: co 有这个问题的解决方案吗?

class VIEwController : UIVIEwController {    let collectionFlowLayout = UICollectionVIEwFlowLayout()    let collectionVIEw = UICollectionVIEw(frame: CGRectZero,collectionVIEwLayout: collectionFlowLayout)}

xcode给我以下错误

VIEwController.swift: 'VIEwController.Type' does not have a member named 'collectionFlowLayout'

我可以使它成为一个可选项并在init方法中初始化它,但我正在寻找一种方法来使collectionvIEw成为let而不是var

解决方法 您可以在初始化程序中将初始值分配给常量成员变量.没有必要使它成为var或optional.

class VIEwController : UIVIEwController {    let collectionFlowLayout = UICollectionVIEwFlowLayout()    let collectionVIEw : UICollectionVIEw    overrIDe init(nibname nibnameOrNil: String?,bundle nibBundleOrNil: NSBundle?)    {        self.collectionVIEw = UICollectionVIEw(frame: CGRectZero,collectionVIEwLayout: self.collectionFlowLayout);        super.init(nibname: nibnameOrNil,bundle: nibBundleOrNil);    }    required init(coder aDecoder: NSCoder) {        fatalError("init(coder:) has not been implemented")    }}
总结

以上是内存溢出为你收集整理的ios – Swift’没有名为’的成员全部内容,希望文章能够帮你解决ios – Swift’没有名为’的成员所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1056293.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存