I have an app that shows data in a 3-column NavigationSplitView, the columns being collections, items in each collection, and item details. Column 2 shows a toolbar button to add a new item. On Mac, that brings up a window where the user can search an online database and choose the data for that new item. But on iOS, Windows aren't allowed (as it says in the debugger when I try running on iPad in the Simulator). I've seen many examples of putting a NavigationStack inside the detail section of the NavigationSplitView. I want that to happen as the result of tapping the toolbar button. When I try, it does slide a new view into place (although it appears to be empty instead of showing the content in my custom View that provides the content for the 2nd window on Mac), and it then immediately slides away to reveal the original detail view.
I'm using the code model presented in a SwiftyPlace example.
class NavigationStateManager: ObservableObject {
@Published var navPath = NavigationPath()
func popToRoot() {
navPath = NavigationPath()
}
func goToSearch() {
self.navPath.append("search");
}
}The main ContentView contains the NavigationSplitView. Its detail contains this:
NavigationStack(path:$nav.navPath) {
if !selectionStore.selectedItems.isEmpty {
DetailView()
}
else {
Text("Select an item.");
}
}
.navigationDestination(for:String.self) { textValue in
if textValue == "search" {
SearchWindow()
.modelContext(modelContext)
}
}Column 2's view handles the toolbar button, which calls this in that same view:
private func addNewIItem()
{
#if os(macOS)
withAnimation {
openWindow(id:"Search");
}
#else
nav.goToSearch();
#endif
}I hope I've added enough of this growing-larger-all-the-time project to show the basic setup. Why is the search view sliding in and then back out? Is there a better way to present another view over the top of the main window/view on iPad and iPhone?
2
0
334