【发布时间】:2014-09-03 10:12:51
【问题描述】:
我是 swift 的新手,并尝试在点击 UIButton 时调用 loginAuth 方法。我所做的与我在 Objective-C 项目中所做的完全一样,但我不断收到以下错误:
[SwiftSwipeView.LoginViewController loginAuth]: unrecognized selector sent to instance
UI按钮
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")
}
【问题讨论】:
-
似乎你在一个项目中混合了objective-c和swift。错误消息看起来像 ObjC,你的 ode 是 Swift。 Swift 错误消息看起来不同。
-
嗯,当我点击 loginAuth 按钮时,错误就会出现,所以我猜错误应该在 loginAuth 方法和 logIn 按钮之间?