我是swift的新手,在第一课中遇到了斯坦福在Swift上使用斯坦福大学开发iOS 9应用程序的问题。我的代码与教师完全相同,但是我收到了一个我似乎无法解决的错误。我认为这可能是Swift 2和3之间的区别,但我不确定。在Swift中按下按钮时出现无法识别的选择器错误
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var display: UILabel!
var userIsInTheMiddleOfTyping: Bool = false
@IBAction func touchDigit(sender: UIButton) {
let digit: String = sender.currentTitle!
if userIsInTheMiddleOfTyping {
let textCurrentlyInDisplay: String = display.text!
display.text = textCurrentlyInDisplay + digit
}
else {
display.text = digit
}
userIsInTheMiddleOfTyping = true
}
}
在模拟器中,我触摸自制计算器上的“数字”按钮,即发生错误时。
你能显示按钮创建代码 –
并显示错误 –
可能重复[IBAction按钮“无法识别选择器发送到实例”错误](http://stackoverflow.com/questions/12783670/baction-button-unrecognized -selector-sent-to-instance-error) –