显示有问题的数组标签和按钮标签



我有一组问题和3个答案,我想在文本标签中显示问题,在每个按钮标签中显示三个答案。文本标签和每个按钮都有一个出口。我是swift的工程师,我很难从阵列中提取

struct Questions {
let allQuestions = [
"The easiest way to learn is:",
"When buying clothes i usually make the decision on the basis of:"
]
let answers = [
[
"By viewing, reading, and observing how the others carry out certain tasks",
"By listening, discussing and doing according to verbal instructions",
"By doing and experimenting by myself",
],
[
"By their appearance and looks",
"Their practicality and use",
"How comfortable they are or how they feel"
]
]
// Initialise your struct
var questions = Questions()
//Keep track of what question you're on. Update this when you reload view
var questionNumber: Int = 0
//Add buttons to outlet collection
@IBOutlet var answerButtons: [UIButton]!
//Populating a question is simple
let aQuestion = questions.allQuestions[questionNumber]
yourQuestionLabel.text = "(aQuestion)"
//For answers, loop through buttons outlet collection
for x in 0..<questions.answers[questionNumber].count {
answerButton[x].titleLabel?.text = "(questions.answers[questionNumber][x])"
}

最新更新