swift_学习中遇到的错误

(1)在VisitorView.swift文件中,懒加载一个按钮:

private var loginButton:UIButton={

        let btn=UIButton()

        btn.setTitle("注册", forState: UIControlState.Normal)

        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: UIControlState.Normal)

        btn.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)

        // 注册监听

        btn.addTarget(self, action: "registerBtnClick", forControlEvents: UIControlEvents.TouchUpInside)

        

        return btn

        }()

运行报错:

Cannot convert value of type 'NSObject -> () -> VisitorView' to expected argument type 'AnyObject?'

报错图片:

 

找了半天,终于发现是忘记加关键字"lazy",改为

private lazy var loginButton:UIButton

 

(2)

posted @ 2016-02-17 22:32  王北城  阅读(287)  评论(0编辑  收藏  举报