当我尝试使用我在代码中创建的按钮时,我不确定为什么会收到“无法识别的选择器发送到类”的错误。
下面是我的代码:
let sendButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("Send", for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.backgroundColor = #colorLiteral(red: 0.5098039216, green: 0.5215686275, blue: 0.8392156863, alpha: 1)
button.layer.cornerRadius = 5
button.isUserInteractionEnabled = true
button.addTarget(self, action: #selector(postComment), for: .touchUpInside)
return button
}()
发布于 2018-06-03 08:26:56
我真的想通了。
出于某种原因,将“let”替换为“lazy var”似乎能起到作用。我不能解释为什么它有效,但它确实有效。
https://stackoverflow.com/questions/50662302
复制相似问题