0

enter image description here

I like the sidebar to be opened at launch.

However when I build and run the app, this is what I get.

enter image description here

So I need to click on the sidebar icon to show it. This is not the behavior I want. Is it possible to change this?

Mark
  • 16,906
  • 20
  • 84
  • 117

1 Answers1

2

Somehow, without explicitly setting it in code, the app likes to change the column visibility to .detailOnly at launch. To avoid this behavior, I explicitly set it to .all at onAppear

@State private var columnVisibility =
    NavigationSplitViewVisibility.all

var body: some View {
    NavigationSplitView(columnVisibility: $columnVisibility) {
        Text("Side bar")
    } detail: {
        Text("Main part")
    }
    .onAppear() {
        columnVisibility = .all
    }
}
Mark
  • 16,906
  • 20
  • 84
  • 117
  • Another option might be to replace `$columnVisibility` with `Binding.constant(.all)`. It seems to work on an iPad but I haven't tried it with macOS. – Mark Moeykens Aug 30 '22 at 14:04