这就是正在发生的事情,我的 Storyboard 中有两个场景,场景一是登录表单,场景二是调用 NSURLSession 的表单(不过该场景不是问题所在)
发生的事情是,当我在第一个场景中单击“登录”按钮时,应用程序崩溃了,应该发生的是应该根据(当前硬编码的)用户凭据检查登录凭据,如果它们正确,应该进行 segue将用户发送到第二个场景。
这是错误日志数据;
2014-10-01 17:24:51.454 TotalSMSAPP[15443:446622] -[TotalSMSAPP.ViewController1 activateLogin:]: unrecognized selector sent to instance 0x7f88d3424620 2014-10-01 17:24:51.459 TotalSMSAPP[15443:446622] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TotalSMSAPP.ViewController1 activateLogin:]: unrecognized selector sent to instance 0x7f88d3424620'
这是适用于问题场景的代码;
import Foundation
import UIKit
class ViewController1: UIViewController {
@IBOutlet var username: UITextField!
@IBOutlet var password: UITextField!
@IBAction func login(sender: UIButton) {
if(username.text == "koharu" && password.text == "test"){
self.performSegueWithIdentifier("toSMS",sender: self)
}else{
}
}
}
最佳答案
'NSInvalidArgumentException',原因:'-[TotalSMSAPP.ViewController1 activateLogin:]:无法识别的选择器发送到实例 0x7f88d3424620'
此错误表明在您定义 login:
时调用了 activateLogin:
。如果您重命名该方法,则可能会发生这种情况。删除按钮操作并使用 @IBAction func login(sender: UIButton)
重新连接它。
关于ios - 按下按钮时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26138213/