gpt4 book ai didi

ios - 如何将数据从数组传递到测验应用程序的多个标签?

转载 作者:行者123 更新时间:2023-11-29 05:47:37 24 4
gpt4 key购买 nike

我应该创建测验应用程序,我刚刚创建了模板和 MVC,但无法理解如何将包含问题和答案的数组中的数据传递到屏幕上的标签?我有3个屏幕1.带有“开始”按钮的屏幕2.主屏幕,我应该从数组传递数据3.屏幕-结果

我附加了模板屏幕 enter image description here

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com