You can use the Section struct to divide a List view into multiple groups. The Section struct takes a single parameter, which is an array of data that will be used to populate the section. Here is an example of how to use Section to divide a list into multiple groups:
List {
Section(header: Text("Section 1")) {
Text("Item 1")
Text("Item 2")
Text("Item 3")
}
Section(header: Text("Section 2")) {
Text("Item 4")
Text("Item 5")
Text("Item 6")
}
}
In the above example, the list is divided into two sections, each with its own header. The first section has a header of "Section 1" and contains three items: "Item 1", "Item 2", and "Item 3". The second section has a header of "Section 2" and contains three items: "Item 4", "Item 5", and "Item 6".
You can also use footer to show footer for each section.
List {
Section(header: Text("Section 1"),footer: Text("This is footer")) {
Text("Item 1")
Text("Item 2")
Text("Item 3")
}
}
Follow me on:
Comments