我是swift的新手,在点击UIButton时尝试调用loginAuth方法。我做的与我在Objective-c项目中所做的完全相同,但我一直在跟踪错误:
[SwiftSwipeView.LoginViewController loginAuth]: unrecognized selector sent to instance
var logIn: UIButton!
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")
}
答案 0 :(得分:2)
您应该在实施时声明目标行动。
改变这个:
logIn.addTarget(self, action: "loginAuth", forControlEvents: .TouchUpInside)
要
logIn.addTarget(self, action: "loginAuth:", forControlEvents: .TouchUpInside)
此消息unrecognized selector sent to instance
始终表示未尝试执行的方法...
答案 1 :(得分:0)
试试这个 (在选择器名称后添加冒号)
logIn.addTarget(self, action: "loginAuth:", forControlEvents: .TouchUpInside)
答案 2 :(得分:0)
试试这个:
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)
正如您的loginAuth期待参数。