我对此非常陌生,经过大量搜索"未解决的标识符"我似乎没有得到这个错误消失。 "未解析的标识符"在" viewDidLoad()"中的函数调用中发生错误在哪里说" startGame()"。
我的基础是本教程:http://www.raywenderlich.com/114262/learn-to-code-ios-apps-with-swift-tutorial-4-your-first-app
该功能应该在应用程序启动时启动倒数计时器。
override func viewDidLoad() {
super.viewDidLoad()
startGame()
//SecondTimerValue.delegate = self
SecondTimerValue.keyboardType = UIKeyboardType.NumberPad
// Do any additional setup after loading the view, typically from a nib.
}
func startGame() {
seconds = 30
count = 0
FirstTimerLabel.text = "Time: \(seconds)"
scoreLabel.text = "Score: \(count)"
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("subtractTime"), userInfo: nil, repeats: true)
}
以下是整个代码。
import UIKit
class ViewController: UIViewController {
@IBOutlet var scoreLabel: UILabel!
@IBOutlet var FirstTimerLabel: UILabel!
@IBOutlet var SecondTimerValue: UITextField!
var count = 0
var seconds = 0
var timer = NSTimer()
var SecondTimerValueVar = 0
// Goal 1 - verify input in text field went to variable
// Goal 2 - get rid of keyboard after "enter"
// Goal 3 - use new value to start new timer
// Goal 4 - When 1st timer reaches zero, start second timer
override func viewDidLoad() {
super.viewDidLoad()
startGame()
//SecondTimerValue.delegate = self
SecondTimerValue.keyboardType = UIKeyboardType.NumberPad
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonPressed(){
SecondTimerValueVar = SecondTimerValue.text.toInt()!
scoreLabel.text = "Score \(count)"
count++
}
@IBAction func startTimerPressed(){
//let SecondTimerValueVar = Int(SecondTimerValue)
}
@IBAction func userTappedBackground(sender: AnyObject) {
view.endEditing(true)
//let a:Int? = Int(firstText.text) // firstText is //UITextField
//let b:Int? = Int(secondText.text) // secondText is UITextField
func startGame() {
seconds = 30
count = 0
FirstTimerLabel.text = "Time: \(seconds)"
scoreLabel.text = "Score: \(count)"
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("subtractTime"), userInfo: nil, repeats: true)
}
func subtractTime (){
seconds--
FirstTimerLabel.text = "Time: \(seconds)"
if (seconds==0) {
timer.invalidate()
}
}
}
答案 0 :(得分:1)
问题在于:
@IBAction func userTappedBackground(sender: AnyObject) {
view.endEditing(true)
func startGame() {
你遗漏了userTappedBackground
的结束花括号,因此startGame
里面的 并且不能被视为方法。< / p>