I've been struggling with this, and user state controlled navigationlink is still not working correctly in Xcode 14.5.1.
I have some views with almost identical functionality, some work, some do not.
What I have discovered is that the views that are the first level of the Navigation stack do not work correctly, but those further down for some reason do work correctly.
NavigationView -> View (with User State Links) // DOES NOT WORK
NavigationView -> NavigationLink -> View (with User State Links) // WORKS
This code demonstrates the problem, and how I have managed to get it working for now by wrapping the view in a container link.
import SwiftUI
let data = ["Item A", "Item B", "Item C"]
struct ContentView: View {
var body: some View {
TabView {
FirstTabView().tabItem {
Image(systemName: "1.circle.fill")
Text("Not working")
}
SecondTabContainerView().tabItem {
Image(systemName: "2.circle.fill")
Text("Working")
}
}
}
}
// First Tab View ** NOT WORKING **
struct FirstTabView: View {
@State private var showingDetailView = false
var body: some View {
NavigationView {
List {
ForEach(data, id: \.self) { data in
NavigationLink(destination: DetailView(data: data)) {
Text(data)
}
}
}
.navigationBarItems(trailing: Button(action: {
showingDetailView = true
}) { Text("Next Page") })
NavigationLink(destination: DetailView(data: "Next Page"), isActive: $showingDetailView) {
EmptyView()
}
}
}
}
struct DetailView: View {
var data: String
var body: some View {
Text(data)
}
}
// Second Tab Views ** WORKING **
struct SecondTabContainerView: View {
@State private var showingDetailView = true
var body: some View {
NavigationView {
NavigationLink(destination: SecondTabView(), isActive: $showingDetailView) { EmptyView() }
}
}
}
struct SecondTabView: View {
@State private var showingDetailView = false
var body: some View {
List {
ForEach(data, id: \.self) { data in
NavigationLink(destination: DetailView(data: data)) {
Text(data)
}
}
}
.listStyle(InsetGroupedListStyle())
.navigationBarItems(trailing: Button(action: {
showingDetailView = true
}) { Text("Next Page") })
.navigationBarBackButtonHidden(true)
NavigationLink(destination: DetailView(data: "Next Page"), isActive: $showingDetailView) {
EmptyView()
}
}
}
Post
Replies
Boosts
Views
Activity
I'm having the same issue every day since last OS update. Macbook Pro 16 with ZMUIPNG USB dock.
"panicFlags" : "0x902",
"panicString" : "panic(cpu 1 caller 0xfffffff013a03448): macOS panic detected\nDebugger message: panic\nMemory ID: 0x6\nOS release type: User\nOS version: 18P4556\nmacOS version: 20E241\nKernel version: Darwin Kernel Version 20.4.0: Thu Mar 4 23:34:36 PST 2021; root:xnu-7195.101.1~1\/RELEASE_ARM64_T8010\nKernel UUID: 3FA744A7-0F34-36DA-AA6D-F6503A3176ED\niBoot version: iBoot-6723.101.4\nsecure boot?: YES\nx86 EFI Boot State: 0xd\nx86 System State: 0x0\nx86 Power State: 0x0\nx86 Shutdown Cause: 0x5\nx86 Previous Power Transitions: 0x304050400\nPCIeUp link state: 0x89271614\nPaniclog version: 13\nKernel slide: 0x000000000bab8000\nKernel text base: 0xfffffff012abc000\nmach_absolute_time: 0x265f479332\nEpoch Time: sec usec\n Boot : 0x60a8eb5e 0x000d6cba\n Sleep : 0x60a9f55a 0x00040aa1\n Wake : 0x60a9f85c 0x0004b7ab\n Calendar: 0x60a9f87e 0x000d8d82\n\nPanicked task 0xffffffe19a150630: 3384 pages, 227 threads: pid 0: kernel_task\nPanicked thread: 0xffffffe19a416a00, backtrace: 0xffffffe804743700, tid: 393\n\t\t lr: 0xfffffff0131ff42c fp: 0xffffffe804743750\n\t\t lr: 0xfffffff0131ff284 fp: 0xffffffe8047437c0\n\t\t lr: 0xfffffff01332a938 fp: 0xffffffe804743890\n\t\t lr: 0xfffffff0138215fc fp: 0xffffffe8047438a0\n\t\t lr: 0xfffffff0131fefb8 fp: 0xffffffe804743c20\n\t\t lr: 0xfffffff0131fefb8 fp: 0xffffffe804743c80\n\t\t lr: 0xfffffff01421f200 fp: 0xffffffe804743ca0\n\t\t lr: 0xfffffff013a03448 fp: 0xffffffe804743cd0\n\t\t lr: 0xfffffff0139f17d8 fp: 0xffffffe804743d30\n\t\t lr: 0xfffffff0139f36d4 fp: 0xffffffe804743dc0\n\t\t lr: 0xfffffff0139f0e7c fp: 0xffffffe804743e50\n\t\t lr: 0xfffffff0138f64c4 fp: 0xffffffe804743e80\n\t\t lr: 0xfffffff01377890c fp: 0xffffffe804743ec0\n\t\t lr: 0xfffffff01377818c fp: 0xffffffe804743f00\n\t\t lr: 0xfffffff01382c5a0 fp: 0x0000000000000000\n\n"
Confirmed as now working again for me.