我是 swift 的新手,尝试在点击 UIButton 时调用 loginAuth 方法。我所做的与我在 Objective-C 项目中所做的完全相同,但我不断收到以下错误:
[SwiftSwipeView.LoginViewController loginAuth]: unrecognized selector sent to instance
界面按钮
var logIn: UIButton!
viewDidLoad
logIn = UIButton(frame: CGRect(x: (self.view.bounds.width/2)-(245/2), y: self.view.bounds.height-200, width: 245.00, height: 37.50));
logIn.backgroundColor = UIColor(red:0.29, green:0.345, blue:0.4, alpha:1)
logIn.setTitle("LOG IN", forState: UIControlState.Normal)
logIn.titleLabel?.font = UIFont(name: "Lato-Bold", size: 14)
logIn.layer.cornerRadius = 5;
logIn.clipsToBounds = true;
logIn.addTarget(self, action: "loginAuth", forControlEvents: .TouchUpInside)
self.view.addSubview(logIn)
登录验证方法
@IBAction func loginAuth(sender: UIButton!) {
println("test")
}
最佳答案
您应该在实现时声明目标操作。
改变这个:
logIn.addTarget(self, action: "loginAuth", forControlEvents: .TouchUpInside)
到
logIn.addTarget(self, action: "loginAuth:", forControlEvents: .TouchUpInside)
此消息 unrecognized selector sent to instance
始终表示未实现要尝试执行的方法...
关于ios - UIButton 不会调用@IBAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25641702/