Hi, This is my first time using a list with different sections. I am using an example from a documented video that I found on the Internet.
I'm getting some weird results. Could someone point me in the right direction?
Here's the code:
import Foundation
struct History: Identifiable, Hashable
{
var id = UUID()
var hist: String
}
struct Titles: Identifiable, Hashable
{
var id = UUID()
var Titl: String
}
struct Library: Identifiable, Hashable
{
var id = UUID()
var lib: String
}
// Main Menu Options:
var commandsA: [History] = [History(hist: "History"),
History(hist: "Overview")]
var commandsB: [Titles] = [Titles(Titl: "Title 1: Employment"),
Titles(Titl: "Title 2: Public Service" ),
Titles(Titl: "Title 3: Public Accommidations"),
Titles(Titl: "Title 4: Telecommunication"),
Titles(Titl: "Title 5: Miscellous")]
var commandsC: [Library] = [Library(lib: "2010 Accessibilty Standards"),
Library(lib: "2008 ADA Amendments"),
Library(lib: "Phone Numbers"),
Library(lib: "More Information")]
struct MainMenu160: View {
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
List {
Section(header: Text("Overview")) {
ForEach(commandsA) { secA in
HStack {
Image(systemName: "folder")
Text("\(secA.hist)")
}.font(.system(size: 20, weight: .bold, design: .rounded))
}
}
}
List {
Section(header: Text("Titles:")) {
ForEach(commandsB) { secB in
HStack {
Image(systemName: "folder")
Text("\(secB.Titl)")
}.font(.system(size: 20, weight: .bold, design: .rounded))
}
}
}
List {
Section(header: Text("Library:")) {
ForEach(commandsC) { secC in
HStack {
Image(systemName: "folder")
Text("\(secC.lib)")
}.font(.system(size: 20, weight: .bold, design: .rounded))
}
}
}.navigationTitle("ADA 1990")
.navigationBarTitleDisplayMode(.automatic)
}
}
struct MainMenu160_Previews: PreviewProvider {
static var previews: some View {
MainMenu160()
}
}
}
And here's the output: