Hi all,
I am new to Swift and I have found an issue which I can't fix.
I use a TabView and if I change the views a few times, and go back to this view I get this error and I can't tab on any of the views any longer in the Navigation Stack.
The way to fix it, is to force close the app and reopen it.
Error message:
"A NavigationLink is presenting a value of type “NavigationItem” but there is no matching navigationDestination declaration visible from the location of the link. The link cannot be activated.
Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView."
Code:
struct ToolsMainView: View {
@State private var navigationPath = NavigationPath()
var body: some View {
NavigationStack(path: $navigationPath) {
VStack {
ScrollView(showsIndicators: false) {
VStack {
ForEach(navigationItems) { item in
NavigationLink(value: item) {
HStack(alignment: .center, spacing: 12) {
Image(systemName: item.icon)
Text(item.title)
Spacer()
Image(systemName: "chevron.right")
}
}
}
}
.scrollTargetLayout()
}
.scrollTargetBehavior(.paging)
}
.navigationDestination(for: NavigationItem.self) { item in
viewMenuItems(item)
}
}
.scrollContentBackground(.hidden)
}
func viewMenuItems(_ tool: NavigationItem) -> some View {
switch tool.menu {
case .forms:
return AnyView(View1())
case .stage:
return AnyView(View2())
case .margin:
return AnyView(View3())
case .vat:
return AnyView(View4())
case .tvheight:
return AnyView(View5))
case .tvsize:
return AnyView(View6())
case .cable:
return AnyView(View7())
case .project:
return AnyView(View8())
case .tasks:
return AnyView(View8())
}
}
}
Do you have any suggestions?
Thank you