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)
它成功编译。
但是,当我用这行编译时,我收到了这个错误..