我可以使用以下代码在 SwiftUI 中创建分组列表:
import SwiftUI
struct ContentView: View {
var body: some View {
List {
Section(header: Text("Freyr / Freya's Aett")) {
}
Section(header: Text("Heimdall's Aett")) {
}
Section(header: Text("Tyr's Aett")) {
}
Section(header: Text("Additional Runes")) {
}
}.listStyle(GroupedListStyle())
}
}
我有一个单独的 swift 文件,它将数据存储在数组中,但我无法将它导入到我的列表中,就像我在 Storyboards 中使用以下代码时那样。
import Foundation
import SwiftUI
struct Rune: Identifiable {
var runeName: String
var runeImage: String
var runeDescription: String
let id = UUID()
}
//MARK: - Runes Array Standard Orientation
var runeTitle = [["Freyr/Freya's Aett"], ["Heimdall's Aett"], ["Tyr's Aett"], ["Additional Runes"]]
let runesArray = [[Rune(runeName: "Fehu", runeImage: String(("Fehu")), runeDescription: "Description Goes Here")],
[Rune(runeName: "Hagalaz", runeImage: String(("Hagalaz")), runeDescription: "Description Goes Here")],
[Rune(runeName: "Tiwaz", runeImage: String(("Tiwaz")), runeDescription: "Description Goes Here")],
[Rune(runeName: "Blank Rune", runeImage: String(("Blank")), runeDescription: "Description Goes Here")]]