UIButton导致编译错误

时间:2016-12-12 06:03:46

标签: swift compilation uibutton add target

 let buttonStr : UIButton = {
    let buttonStr = UIButton(type: .system) as UIButton
    buttonStr.backgroundColor = .black
    buttonStr.addTarget(self, action: #selector(buttonAction(sender:)), for: .touchUpInside)
    buttonStr.translatesAutoresizingMaskIntoConstraints = false
    buttonStr.setBackgroundImage(#imageLiteral(resourceName: "button") ,for: UIControlState.normal)
    buttonStr.imageView?.contentMode = .scaleAspectFit


    return buttonStr
}()

func buttonAction(sender:UIButton) {
    print("hi")
}

当我删除此行

buttonStr.addTarget(self, action: #selector(buttonAction(sender:)), for: .touchUpInside)

它成功编译。

但是,当我用这行编译时,我收到了这个错误..

enter image description here

0 个答案:

没有答案