Why does my swiftUI app crash when navigating backwards after placing a NavigationLink insiede of a NavigationBarItems?
NavigationView { Text("Hello World") .navigationBarItems( trailing: NavigationLink(destination: Child()) { Image("myImageName"}) }
This appears as a workaround, waiting for the bug to be corrected (you may have to read the whole post as it references some other code (Robert's Parent View):
It looks like the issue revolves around the Nav Bar and the way the buttons were added to it. So instead of using a NavigationLink() for the button itself, I tried using a standard Button() with an action that sets a @State var that activates a hidden NavigationLink. Here is a replacement for Robert's Parent View:
struct Parent: View { @State private var showingChildView = false var body: some View { NavigationView { VStack { Text("Hello World") NavigationLink(destination: Child(), isActive: self.$showingChildView) { EmptyView() } .frame(width: 0, height: 0) .disabled(true) } .navigationBarItems( trailing: Button(action:{ self.showingChildView = true }) { Text("Next") } ) } } }
So you should:
- comment out your present code and add comment as "Waiting for iOS 13.2 bug correction" (to be able to restore when bug is finally corrected)
- replace by something similar to this one
- test and report