Post

Replies

Boosts

Views

Activity

Reply to Embedding a NavigationStack within the detail view of a NavigationSplitView
Thanks for your reply - I've submitted FB12171134. Here's a minimal code example to reproduce (I appreciate the Stack here doesn't achieve anything, but the behaviour is the same): class Row: Identifiable, Hashable { let id: UUID let title: String init(title: String) { self.id = UUID() self.title = title } static func == (lhs: Row, rhs: Row) -> Bool { return lhs.id == rhs.id } func hash(into hasher: inout Hasher) { hasher.combine(id) } } struct ContentView: View { let rows = [Row(title: "Row 1"), Row(title: "Row 2"), Row(title: "Row 3")] @State var selectedRow: Row? var body: some View { NavigationSplitView { List(selection: $selectedRow) { ForEach(rows) { row in NavigationLink(value: row) { Text(row.title) } } } .navigationTitle("Root List") } detail: { if let selectedRow = selectedRow { RowView(row: selectedRow) } } } } import SwiftUI struct RowView: View { let row: Row var body: some View { NavigationStack { VStack { Text("Detail View") } .navigationTitle(row.title) .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button { // Empty } label: { Label("Add", systemImage: "plus") } } } } } }
May ’23