当我将List
分组嵌入到Section
s中时NavigationView
,节标题变得可折叠。我想让它们不可折叠,List
就像NavigationView
.
我当前的代码(使用 NavigationView):
import SwiftUI
struct MyGroup {
var name:String, items:[String]
}
struct ContentView: View {
var groups : [MyGroup] = [
.init(name: "Animals", items: ["","","","","","","",""]),
.init(name: "Vehicles", items: ["","","","","","","","⛵️"])]
var body: some View {
NavigationView {
VStack {
List {
ForEach(groups, id: \.self.name) { group in
Section(header: Text(group.name)) {
ForEach(group.items, id:\.self) { item in
Text(item)
}
}
}
}
}.navigationTitle("collections")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}