import UIKit
class ViewController: UIViewController {
@IBOutlet weak var QuestionLabel: UILabel!
@IBOutlet weak var Button1: UIButton!
@IBOutlet weak var Button2: UIButton!
@IBOutlet weak var Button3: UIButton!
@IBOutlet weak 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 RandomQuestions(){
var RandomNumber = arc4random() % 4
RandomNumber += 1
switch(RandomNumber){
case 1:
QuestionLabel.text = "Who is the best soccer player in the world?"
Button1.setTitle("Messi", forState: UIControlState.Normal)
Button2.setTitle("Neymar", forState: UIControlState.Normal)
Button3.setTitle("Bale", forState: UIControlState.Normal)
Button4.setTitle("James", forState: UIControlState.Normal)
CorrectAnswer = "2"
break
case 2:
QuestionLabel.text = "How many goals is a hat trick?"
Button1.setTitle("2", forState: UIControlState.Normal)
Button2.setTitle("5", forState: UIControlState.Normal)
Button3.setTitle("3", forState: UIControlState.Normal)
Button4.setTitle("7", forState: UIControlState.Normal)
CorrectAnswer = "3"
break
case 3:
QuestionLabel.text = "What number is Neymar?"
Button1.setTitle("2", forState: UIControlState.Normal)
Button2.setTitle("5", forState: UIControlState.Normal)
Button3.setTitle("3", forState: UIControlState.Normal)
Button4.setTitle("11", forState: UIControlState.Normal)
CorrectAnswer = "4"
break
case 4:
QuestionLabel.text = "What number is messi?"
Button1.setTitle("2", forState: UIControlState.Normal)
Button2.setTitle("10", forState: UIControlState.Normal)
Button3.setTitle("3", forState: UIControlState.Normal)
Button4.setTitle("7", forState: UIControlState.Normal)
CorrectAnswer = "2"
break
default:
break
}
}
@IBAction func Button1Action(sender: AnyObject) {
if (CorrectAnswer == "1"){
NSLog("You Are Correct")
}
else{
NSLog("YOu Are Wrong")
}
}
@IBAction func Button2Action(sender: AnyObject) {
if (CorrectAnswer == "2"){
NSLog("You Are Correct")
}
else{
NSLog("YOu Are Wrong")
}
}
@IBAction func Button3Action(sender: AnyObject) {
if (CorrectAnswer == "3"){
NSLog("You Are Correct")
}
else{
NSLog("YOu Are Wrong")
}
}
@IBAction func Button4Action(sender: AnyObject) {
if (CorrectAnswer == "4"){
NSLog("You Are Correct")
}
else{
NSLog("You Are Correct")
}
}
任何人都可以帮助我,我需要编码,我需要帮助。我已经找到了我放的任何额外的括号,我没有看到任何帮助?
答案 0 :(得分:1)
此类功能的一个有用功能是右键单击文件中的某个位置,然后选择" Structure-> Balance Delimiter"从弹出菜单中。这将突出显示开始和结束分隔符之间的所有代码。如果缺少该代码块的分隔符,它将发出哔哔声。
在您的情况下,您缺少类定义本身的右括号。