I have a TabView within a NavigationStack, and the child views of the TabView contain NavigationLinks and NavigationDestinations. The issue I'm running into is, when tab 1 is the starting view of the TabView, only the NavigationDestinations on tab 1 work. If I start with the TabView displaying tab 2 or 3, the NavigationDestinations on Tabs 1, 2, and 3 all work properly.
When starting on tab 1, the error I receive when tapping the NavigationLink on Tab 2 (when it doesn't work) is "A NavigationLink is presenting a value of type “Int” but there is no matching navigation destination visible from the location of the link. The link cannot be activated."
I don't think there's anything wrong with the actual NavigationLinks or NavigationDestinations themselves, since it works when launching on tabs 2 or 3, but I cannot for the life of me figure out why starting at tab 1 doesn't work.
struct MainView: View {
@State private var selectedView: Int = 1
@Binding var taskList: [ToDoTask]
@Binding var projectList: [Project]
@EnvironmentObject var projectStore: Project.projectList
@Environment(\.scenePhase) private var scenePhase
@State private var navPath = NavigationPath()
var body: some View {
NavigationStack(path: $navPath) {
TabView(selection: $selectedView) {
NavigationView {
ContentView(taskList: $taskList, projectList: $projectList)
}
.tabItem { Label("Focus", systemImage: "star.fill")
}
.tag(1)
NavigationView {
ProcessView(taskList: $taskList, projectList: $projectList)
}
.tabItem { Label("Refocus", systemImage: "arrow.left.arrow.right") }
.tag(2)
NavigationView {
ReorganizationView(projectList: $projectList, taskList: $taskList)
}
.tabItem { Label("Reorganize", systemImage: "exclamationmark.3") }
.tag(3)
}
.accentColor(Color("ListColor"))
.onChange(of: scenePhase) { phase in
if phase == .background {
FileSaveLoad.saveTasks(tasks: taskList) { result in
if case .failure(let error) = result {
fatalError(String("\(error)"))
}
}
FileSaveLoad.saveProjects(projects: projectList) { result in
if case .failure(let error) = result {
fatalError(String("\(error)"))
}
}
}
}
}
}
}