0
第一次構建一個應用程序,所以請原諒,如果這是一個微不足道的修復。我已經在youtube上尋找幫助,使用Google搜索,並搜索StackOverflow,但是在嘗試構建時似乎沒有修復錯誤。有人能夠看看我告訴我哪裏出錯了嗎?看看這個工作副本我找不到差異= \測驗應用程序 - 連續聲明錯誤
我得到的錯誤是(主要是案例2 /案例3行): - 行上的連續陳述必須由' ;」 -Expected表達 - 使用未解決的識別符「RandomQuestions」 - 使用未解決的識別符的「外殼2」(和「情況下3」)
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var QuestionLabel: UILabel!
@IBOutlet var Button1: UIButton!
@IBOutlet var Button2: UIButton!
@IBOutlet var Button3: UIButton!
@IBOutlet var Button4: UIButton!
var CorrectAnswer = String()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
RandomQuestions()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func RandomQuestioins(){
var RandomNumber = arc4random() % 4
RandomNumber += 1
switch(RandomNumber){
case 1:
QuestionLabel.text = "Hello World, What Is My Name?"
Button1.setTitle("John", forState: UIControlState.Normal)
Button2.setTitle("Ryan", forState: UIControlState.Normal)
Button3.setTitle("Alex", forState: UIControlState.Normal)
Button4.setTitle("Google", forState: UIControlState.Normal)
CorrectAnswer = "2"
break
case2:
QuestionLabel.text = "What country do you live in?"
Button1.setTitle("Russia", forState: UIControlState.Normal)
Button2.setTitle("Good Question", forState: UIControlState.Normal)
Button3.setTitle("USA", forState: UIControlState.Normal)
Button4.setTitle("Mexico", forState: UIControlState.Normal)
CorrectAnswer = "3"
break
case3:
QuestionLabel.text = "What day is it?"
Button1.setTitle("Saturday", forState: UIControlState.Normal)
Button2.setTitle("Sunday", forState: UIControlState.Normal)
Button3.setTitle("Monday", forState: UIControlState.Normal)
Button4.setTitle("Thusday", forState: UIControlState.Normal)
CorrectAnswer = "2"
break
case 4:
QuestionLabel.text = "What is your favorite color?"
Button1.setTitle("Blue", forState: UIControlState.Normal)
Button2.setTitle("Red", forState: UIControlState.Normal)
Button3.setTitle("Green", forState: UIControlState.Normal)
Button4.setTitle("Yellow", forState: UIControlState.Normal)
CorrectAnswer = "1"
break
default:
break
}
}
@IBAction func Button1Action(sender: AnyObject) {
if (CorrectAnswer == "1"){
NSLog("Correct")
}
else{
NSLog("Try Again!")
}
}
@IBAction func Button2Action(sender: AnyObject) {
if (CorrectAnswer == "2"){
NSLog("Correct")
}
else{
NSLog("Try Again!")
}
}
@IBAction func Button3Action(sender: AnyObject) {
if (CorrectAnswer == "3"){
NSLog("Correct")
}
else{
NSLog("Try Again!")
}
}
@IBAction func Button4Action(sender: AnyObject) {
if (CorrectAnswer == "4"){
NSLog("Correct")
}
else{
NSLog("Try Again!")
}
}
}
非常感謝您的評論!只要你指出,我很快就看到了我做錯了什麼。似乎很明顯,現在哈哈只是缺乏對細節的關注。 – Babou16
嗯,你確實提到你是新的,每個人都從某個地方開始。保持 :) – Happiehappie