NavigationSplitView sidebar Links not working after navigating back

Hi there,

I'm struggling with the new NavigationSplitView.


struct Team: Identifiable, Hashable {
    let id = UUID()
    var name: String
    var players: [String]
}
struct SplitView3: View {

    @State private var teams = [
          Team(name: "Packers", players: ["Rodgers", "Alexander", "Dillon"]),
          Team(name: "Vikings", players: ["Ingram", "Cousins", "Berry"])
    ]
    @State private var selectedTeam: Team?
    @State private var selectedPlayer: String?
        var body: some View {
            NavigationSplitView {
                List(teams, selection: $selectedTeam) { team in
                    Text(team.name).tag(team).navigationTitle("Team")
                }.navigationBarHidden(true)
                .navigationSplitViewColumnWidth(250)
            } content: {
                List(selectedTeam?.players ?? [], id: \.self, selection: $selectedPlayer) { player in
                    Text(player).navigationTitle("Team Member")
                }
            } detail: {
                Form{
                    Text(selectedPlayer ?? "Choose a player.")
                }
                .navigationTitle("Player Detail").navigationBarTitleDisplayMode(.inline)
            }
            .navigationSplitViewStyle(.automatic)
        }
}

When I run this in Simulator or Canvas I can navigate from Team (sidebar), trough Teammembers (content) to detail view and back to sidebar. But after I reach the sidebar again the links forward to content view don't work anymore.

Did I miss something?

On IPadOS it works as supposed, forward and backward navigations works

iOS & iPadOS 16 Beta Release Notes

SwiftUI

Known Issues

• Selection-driven, three-column NavigationSplitView sometimes fails to push when collapsed to a single column. (93673059)

Facing the same problem even on Xcode Beta 2

I expect this to be fixed as its already identified by Apple as a bug as mentiond by BabyJ.

For the time being you may reset selectedTeam back to nil with a button defined somewhere in your ViewBuilder closure that sets up the sidebar. (For testing purposes of NavigationSplitView). This allows to trigger a new Navigation after the reset.

My observations were the following:

  • Navigating back from the detail view triggers a navigation and sets selectedPlayers back to nil
  • Navigating back from the content view triggers a navigation back but does NOT set selectedTeam back to nil. This also explains why a team is still selected after navigation back to the sidebar view.

The missing reset to nil of selectedTeam also is the reason why it is not possible to detect a back navigation to the sidebar programmatically and the button to reset selectedTeam back to nil was the only option for me. Hopefully this gets fixed till the release of iOS 16, to be able to use NavigationSplitView accross all device types and size classes.

I am actully confused why there is no collapse button to show/hide the sidebar in NavigationSplitView. Tutorials show it but when i copy the code and run it, there is no collapse button. Only the navigation links are shown full width and height. the detail view is nowhere to be seen.

Works fine on Xcode 14.1 simulator

NavigationSplitView sidebar Links not working after navigating back
 
 
Q