过去,我以编程方式创建 UIButton 没有问题,但自从我使用 Xcode 9 和 Swift 4 以来,我就找不到解决这个错误的方法。
//Adding target to UIButton
func PositionStartButton(xOffset: Float){
StartButton.frame = CGRect(x: Int(0 - 40 + xOffset), y: 0, width: 80, height: 80)
StartButton.setImage(#imageLiteral(resourceName: "Logo_Final_WHITE_Face"), for: .normal)
StartButton.addTarget(self, action: "pressButton:", for: .touchUpInside)
ScrollView.addSubview(StartButton)
}
//The target function
func pressButton(_ sender: UIButton){
print("\(sender)")
}
错误消息:'NSInvalidArgumentException',原因:'-[Playing.MainMenuViewController pressButton:]:无法识别的选择器发送到实例 0x10440a6b0'