1

After a couple of days struggling with programmatic navigation in SwiftUI and 3 column NavigationSplitView I found that .navigationDestination(isPresented:destination:) works only between sidebar and master or between master and detail, but can't be used in both. It can be illustrated on the following example:

struct ContentView: View {
  @State private var columnVisibility = NavigationSplitViewVisibility.all
  @State private var showMaster = false
  @State private var showDetails = false

  var body: some View {
    NavigationSplitView(columnVisibility: $columnVisibility) {
      Button("Show master") {
        showMaster = true
      }
      .navigationDestination(isPresented: $showMaster) {
        Button("Show details") {
          showDetails = true
        }
        .navigationDestination(isPresented: $showDetails) {
          Text("Detail")
        }
      }
    } content: {
      EmptyView()
    } detail: {
      EmptyView()
    }
  }
}

enter image description here

When I execute the code and click on "show master" button, it correctly shows "show detail" button. If I click on "show detail" button I expected "detail" will show, but nothing happens. What am I doing wrong?

It works correctly if only .navigationDestination(for:destination:). It doesn't work even if .navigationDestination(isPresented:destination:) is used to show master.

  • I've run into the same problem. What does work is putting the `.navigationDestination` in a StackView in the detail column. But I want to replace, not push. With the `.navigationDestination` in the detail column, I get .... > A `navigationDestination(isPresented:content:)` is outside an explicit NavigationStack, but inside the detail column of a NavigationSplitView, so it attempts to target the next column. There is no next column after the detail column. However if I put the same `.navigationDestination` the content column block, it doesn't actually target the next column. – Scott Ahten Apr 04 '23 at 20:35

0 Answers0