ios - UIButton 不会调用@IBAction

标签 ios swift uibutton

我是 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/

相关文章:

ios - 修复 iOS 中的多个按钮单击事件?

ios 6 : NSLayoutConstraint issue in iphone 5. 1 模拟器

ios - 从 xib 实例化自定义表格 View 单元格失败

ios - 如何在 SpriteKit Swift 4 中制作垂直无限滚动背景

swift - 如何在 swift 中将带变音符号的 AttributedString 保存为正确的 RTF?

ios - 如何更改特定 TableViewCell 中的按钮颜色

objective-c - UI 设置代码在哪里?

ios - #ifdef 语句检查测试方案

java - AWS appium ios 测试总是失败

swift - NSNumber 不是 UInt8 的子类型