我在 Swift 2.2 中开发了一个项目,在 Swift 3 启动后我需要在 Swift 3 中转换它并使其可与 iOS 10 编译。但是在转换项目之后我遇到了一些问题,比如当我点击与 Storyboard连接的按钮时我的应用程序崩溃,原因是 unrecognized selector sent to instance 。它在 swift 2.2 中工作,我没有改变任何东西。
@IBAction func btnTwitter_Clicked(sender:UIButton)
{
if checkInternetConnection()
{
SINGLETON.startLoadingActivity(self.view);
let objLocationTracker = LocationTracker.sharedInstance
objLocationTracker.fetchCurrentLocation({ (objLocation) -> (Void) in
SINGLETON.stopLoadingActivity(self.view)
self.loginWithTwitter(objLocation: objLocation)
})
}
else
{
SINGLETON.toast(read_Localizable("noInternet"),view: self.view)
}
}
最佳答案
看到这个
@@IBAction func btnTwitter_Clicked(sender:UIButton) 你在按钮前面添加了额外的 @,检查一次,
在swift3中我们需要像这样写按钮 Action
yourbuttonName.addTarget(self, action: #selector(yourVCName. btnTwitter_Clicked(_:)), for: .touchUpInside)
和调用方法一样
@IBAction func btnTwitter_Clicked(_ sender: UIButton){
print("Button pressed 👍 ")
// continue your work
}
或者把按钮Outlets和IBActions删掉,重新生成一次,肯定有效
关于ios - 在 swift 3 中,按钮单击应用程序崩溃,与 Storyboard绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39739079/