Post

Replies

Boosts

Views

Activity

Reply to DocumentBrowser toolbar behavior in SwiftUI apps
Hi Ziqiao, the problem is that when you want to use SwiftData for an enterprise app, the user needs proper navigation. In such apps, you usually have more than one screen or form. I did some additional tests with your code and replaced the NavigationStack with a NavigationView. The reason is that I need the automatic two-column split for a sidebar menu and a detail view, not just a single view. The NavigationSplitView doesn’t seem to work as expected. Using it as a root view with an embedded TabView was my first attempt, but that didn’t work either. That’s why I tried embedding the NavigationSplitViews inside the TabView. When I replace your NavigationStack with a NavigationView, I get the automatic two-column view on iPad — but with a second navigation view below the DocumentGroup navigation view. This looks bugged. The NavigationSplitView also has issues with the back button and the document title in sheets. I’ll file a feedback report for now as you suggested and try to find a workaround for my app, maybe with a custom sidebar built as an HStack. But thanks for your help with this problem.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
2w
Reply to DocumentBrowser toolbar behavior in SwiftUI apps
Hi Ziqiao, thanks for the code snippet — it also works well in my app. I only made a few small changes: I’m using NavigationSplitView instead of NavigationStack, and placing the List inside the navigation view slightly changes the appearance of the navigation bar. It now returns directly from the detail view to the document browser. Also, the sheets and full-screen covers you present should now show the document title and back buttons in their navigation bars. Xcode 16.4 iOS 18.3 iPhone 18 Pro (Simulator) struct ContentView: View { private enum Row: Hashable { case details } @State private var selection: Row? var body: some View { TabView { Tab("Rectangle", systemImage: "rectangle") { NavigationSplitView { List(selection: $selection) { NavigationLink(value: Row.details) { Text("Tap to see details") } } .toolbar { ToolbarItem(placement: .topBarTrailing) { Button("Add") { print("Button pressed.") } } } } detail: { switch selection { case .details: Text("Details") default: Text("Select something") } } } Tab("Circle", systemImage: "circle") { NavigationStack { Text("Circle") .toolbar { ToolbarItem(placement: .topBarTrailing) { Button("Remove") { print("Button pressed.") } } } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
2w