您好我正在尝试创建一个简单的测验应用程序,但我收到一个错误,它没有显示或增加ui标签中的问题,但它打印答案。我知道我很亲密,我找不到问题。如果你能帮助我,我会非常感激。我知道这可能是一个愚蠢的错误
import UIKit
struct Quiz{
var question: String!
var options: [String]!
var answer: Int!
}
class QuizViewController: UIViewController {
@IBOutlet weak var QuestionLabel: UILabel!
@IBOutlet var Options: [UIButton]!
var questions = [Quiz]()
var qNumber = Int()
var answerNumber = Int()
override func viewDidLoad() {
super.viewDidLoad()
questions = [Quiz(question: "What is your name?", options: ["AJ","Sami","Daniel","Sazzad"], answer: 1),
Quiz(question: "What is your colour?", options: ["red","green","blue","orange"], answer: 2),
Quiz(question: "What is your pets name?", options: ["Kitty","Marley","Button","Snoopy"], answer: 0),
Quiz(question: "What is your flat number?", options: ["204","205","208","209"], answer: 3)]
selectQuestion()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func selectQuestion(){
if questions.count<0{
qNumber = 0
QuestionLabel.text = questions[qNumber].question
answerNumber = questions[qNumber].answer
for i in 0..<Options.count{
Options[i].setTitle(questions[qNumber].options[i], for: UIControlState.normal)
}
questions.remove(at: qNumber)
}
else{
NSLog("Quiz is completed")
}
}
@IBAction func Option1(_ sender: Any) {
if answerNumber == 0{
selectQuestion()
}
else{
NSLog("Incorrect Answer")
}
}
@IBAction func Option2(_ sender: Any) {
if answerNumber == 1{
selectQuestion()
}
else{
NSLog("Incorrect Answer")
}
}
@IBAction func Option3(_ sender: Any) {
if answerNumber == 2{
selectQuestion()
}
else{
NSLog("Incorrect Answer")
}
}
@IBAction func Option4(_ sender: Any) {
if answerNumber == 3{
selectQuestion()
}
else{
NSLog("Incorrect Answer")
}
}