Я новичок в IOS Development и внедряю приложение IOS QUIZ.
Как обновить вопрос и ответы в приложении QUIZ.
Пожалуйста, проверьте ниже мой код, это то, как я отображаю.
@IBOutlet weak var prevBtn: UIButton!
@IBOutlet weak var nxtBtn: UIButton!
@IBOutlet weak var qstnlbl: UILabel!
@IBOutlet weak var answerABtn: UIButton!
@IBOutlet weak var answerBBtn: UIButton!
@IBOutlet weak var answerCBtn: UIButton!
@IBOutlet weak var answerDBtn: UIButton!
let questions = ["How many days are there in 1 year?", "Favorite color?", "Where was I born?"]
let answers = [["360", "365", "384", "377"], ["blue", "black", "green", "orange"], ["Tokyo", "New York", "Tennessee", "rajahmundry"]]
//Variables
var currentQuestion = 0
var rightAnswerPlacement:UInt32 = 0
var points = 0;
//Label
@IBOutlet weak var lbl: UILabel!
//Button
@IBAction func action(_ sender: AnyObject)
{
if (sender.tag == Int(rightAnswerPlacement))
{
print ("RIGHT!")
points += 1
}
else
{
print ("WRONG!!!!!!")
}
if (currentQuestion != questions.count)
{
newQuestion()
}
}
@IBAction func preAction(_ sender: AnyObject)
{
if (currentQuestion != questions.count)
{
newQuestion()
}
currentQuestion = currentQuestion - 1
}
@IBAction func nxtaction(_ sender: AnyObject)
{
if (currentQuestion != questions.count)
{
newQuestion()
}
currentQuestion = currentQuestion + 1
}
override func viewDidAppear(_ animated: Bool)
{
newQuestion()
}
//Function that displays new question
func newQuestion()
{
qstnlbl.text = questions[currentQuestion]
rightAnswerPlacement = arc4random_uniform(3)+1
//Create a button
var button:UIButton = UIButton()
var x = 1
for i in 1...4
{
//Create a button
button = view.viewWithTag(i) as! UIButton
button.setTitle(answers[currentQuestion][x], for: .normal)
x = 2
}
currentQuestion += 1
}
на основе ответов, выбранных пользователем, необходимо добавить в answerArray.
Например: если пользователь выбирает в первом вопросе в answerABtn вариант ответа «A», answerArray должен обновляться с «A"значение.
пользователь может обновить ответ
для примера: пользователь выбирает первый вариант ответа на вопрос" b "answerArray должен обновить значение" b ".
пожалуйстапомогите мне сделать это приложение викторины.
интерфейс приложения викторины
введите описание изображения здесь