【问题标题】:How to resolve this error? - Class 'ViewController' has no initializers如何解决此错误? - 类 'ViewController' 没有初始化器
【发布时间】:2015-08-03 06:25:36
【问题描述】:

我在 swift 中以编程方式创建了UILabel,但它给了我以下错误:

“ViewController”类没有初始化器

代码:

class ViewController: UIViewController {

    let lbl_LastName: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        lbl_LastName.frame = CGRectMake(10, 230, 300, 21)
        self.view.addSubview(lbl_LastName)   
    }
}

【问题讨论】:

    标签: ios swift uilabel


    【解决方案1】:

    let lbl_LastName: UILabel! 更改为var lbl_LastName: UILabel!

    【讨论】:

    • 正确答案,但你能解释一下解决方案吗?
    猜你喜欢
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    相关资源
    最近更新 更多