Ask Your Question
1

How can the collapsibility of List Sections in SwiftUI be disabled when used within a NavigationView?

asked 2021-09-02 11:00:00 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-02-23 12:00:00 +0000

pufferfish gravatar image

To disable the collapsibility of List Sections in SwiftUI when used within a NavigationView, you can use the following modifier on the List:

.listStyle(GroupedListStyle())

By using the GroupedListStyle(), you can prevent the List Sections from collapsing when using a NavigationView. The code would look something like this:

NavigationView {
    List {
        Section(header: Text("Section 1")) {
            Text("Item 1")
            Text("Item 2")
        }
        Section(header: Text("Section 2")) {
            Text("Item 3")
            Text("Item 4")
        }
    }
    .listStyle(GroupedListStyle())
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-09-02 11:00:00 +0000

Seen: 11 times

Last updated: Feb 23 '23