Post

Replies

Boosts

Views

Activity

Reply to Driving NavigationSplitView with something other than List?
Maybe this can help someone, not sure if the binding set closure setting the value back to nil will work for all scenarios. struct ContentView: View { enum DetailScreen { case first } @State private var selectedDetails: DetailScreen? @State private var preferredColumn = NavigationSplitViewColumn.detail var body: some View { NavigationSplitView( preferredCompactColumn: .init( get: { selectedDetails != nil ? .detail : .sidebar }, set: { _ in selectedDetails = nil } ) ) { Button("First") { selectedDetails = .first } } detail: { switch selectedDetails { case .first: Text("First") case nil: Text("Select something") } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’26
Reply to Driving NavigationSplitView with something other than List?
Maybe this can help someone, not sure if the binding set closure setting the value back to nil will work for all scenarios. struct ContentView: View { enum DetailScreen { case first } @State private var selectedDetails: DetailScreen? @State private var preferredColumn = NavigationSplitViewColumn.detail var body: some View { NavigationSplitView( preferredCompactColumn: .init( get: { selectedDetails != nil ? .detail : .sidebar }, set: { _ in selectedDetails = nil } ) ) { Button("First") { selectedDetails = .first } } detail: { switch selectedDetails { case .first: Text("First") case nil: Text("Select something") } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’26