我应该创建测验应用程序,我刚刚创建了模板和 MVC,但无法理解如何将包含问题和答案的数组中的数据传递到屏幕上的标签? 我有3个屏幕 1.带有“开始”按钮的屏幕 2.主屏幕,我应该从数组传递数据 3.屏幕-结果
struct Question {
var text: String
var answers: [Answer]
}
extension Question {
static func loadData() -> [Question] {
return [
Question(
text:some text",
answers: [
Answer(text: "some text", type: .Sloupok),
Answer(text: "some text", type: .Pikachy),
Answer(text: "some text", type: .Lucario),
Answer(text: "some text", type: .Slugma),
Answer(text: "some text", type: .Vaperon)
]
),
Question(
text:"some text",
answers: [
Answer(text: "some text", type: .Sloupok),
Answer(text: "some text", type: .Pikachy),
Answer(text: "some text", type: .Lucario),
Answer(text: "some text", type: .Slugma),
Answer(text: "some text", type: .Vaperon)
]
),
Question(
text:"some text ?",
answers: [
Answer(text: "some text", type: .Sloupok),
Answer(text: "some text", type: .Pikachy),
Answer(text: "some text", type: .Lucario),
Answer(text: "some text", type: .Slugma),
Answer(text: "", type: .Vaperon)
]
),
Question(
text:"some text?",
answers: [
Answer(text: "some text", type: .Sloupok),
Answer(text: "some text", type: .Pikachy),
Answer(text: "Сsome text", type: .Lucario),
Answer(text: "some text", type: .Slugma),
Answer(text: "some text", type: .Vaperon)
]
),
Question(
text:"some text?",
answers: [
Answer(text: "some text", type: .Sloupok),
Answer(text: "some text", type: .Pikachy),
Answer(text: "some text", type: .Lucario),
Answer(text: "some text", type: .Slugma),
Answer(text: "some text", type: .Vaperon)
]
)
]
}
}
最佳答案
您可以将数据一一设置为标签,但这不是一个好的解决方案。如果您需要动态数量的答案,则传递数据就会变得复杂。
我建议使用TableView。您可以创建自定义单元格来显示答案并在表格 View 中使用它。 这是使用 TableView 的好例子:UITableView example for Swift
关于ios - 如何将数据从数组传递到测验应用程序的多个标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55990295/